java - ImageMagick: converting piped images -
i'm attempting convert image in inputstream outputstream using im4java. docs, looks setting inputprovider input , specifying output stream should pipe converted image, a:
failed convert image: more argument images placeholders
here's function:
public static inputstream convert(inputstream imagestream){ seek { // set im4java properties. see {@link im4java} imoperation op = new imoperation(); op.scale(1000); op.compress("zip"); convertcmd convert = new convertcmd(); convert.setsearchpath(imlocation); logger.debug("imagemagick located at: " + convert.getsearchpath()); inputstream = imagestream; bytearrayoutputstream os = new bytearrayoutputstream(); pipe pipein = new pipe (is, null); pipe pipeout = new pipe(null, os); convert.setinputprovider(pipein); convert.setoutputconsumer(pipeout); convert.run(op, "-", "pdf:-"); is.close(); os.close(); pipeout.consumeoutput(is); homecoming is; }catch(exception e){ logger.debug("failed convert image: " + e.getmessage()); } homecoming null; }
thanks!
solved it, posting here posterity.
public static inputstream convert(string path, inputstream imagestream){ seek { imoperation op = new imoperation(); op.compress("zip"); //order matters here, create sure colorspace first arg set inputstream = imagestream; pipe pipein = new pipe (is, null); bytearrayoutputstream os = new bytearrayoutputstream(); pipe pipeout = new pipe(null, os); convertcmd convert = new convertcmd(); convert.setsearchpath(imlocation); convert.setinputprovider(pipein); convert.setoutputconsumer(pipeout); op.addimage("-"); op.addimage("pdf:-"); // execute operation final long starttime = system.nanotime(); convert.run(op); final long endtime = system.nanotime(); logger.debug("compressed"); logger.debug("done converting " + path); final long elapsedtimeinms = (endtime - starttime) / 1000000; logger.debug("took " + elapsedtimeinms); homecoming new bytearrayinputstream(os.tobytearray()); }catch(exception e){ logger.debug("failed convert image: " + e.getmessage()); } homecoming null; }
java imagemagick im4java
No comments:
Post a Comment