I am constructing a PSD with multiple layers using imagemagick. That works for me using the CLI command convert 1.png 1.png 2.png test.psd
. (the extra 1.png is there because the first layer of a PSD is the flattened result of all layers)
I want to do it using im4java, without actually saving the images to the disk (using InputStream). That should be possible with an input Pipe initialized with an InputStream. However, it only works for me with one input image. If I have several, I don't know how to pass them all as input to the process' stdin.
I tried concatenating my image input streams using the java.io.SequenceInputStream
, but this result in an error:
org.im4java.core.CommandException: convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
My code:
FileInputStream imageStream1 = new FileInputStream("1.png");
FileInputStream imageStream2 = new FileInputStream("2.png");
InputStream concatStreams = new SequenceInputStream(imageStream1, imageStream2);
IMOperation op = new IMOperation();
// "-" means to read the image from stdin
op.addImage("-"); // the first, "dummy" image
op.addImage("-"); // 1.png
op.addImage("-"); // 2.png
// output in PSD format to stdout
op.addImage("psd:-");
ConvertCmd cmd = new ConvertCmd();
Pipe pipeIn = new Pipe(concatStreams, null);
cmd.setInputProvider(pipeIn);
// omitted cmd.setOutputConsumer code
cmd.run(op);