Reputation: 1096
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);
Upvotes: 5
Views: 1343
Reputation: 695
I know this is a very old question but I ended up here from a google search so I thought it might be worth answering.
I solved it by loading the input as java.awt.image.BufferedImage instead of streams.
BufferedImage image1 = ImageIO.read("1.png");
BufferedImage image2 = ImageIO.read("2.png");
IMOperation op = new IMOperation();
// No argument means to use images given in cmd.run.
// These can be either BufferedImage instances or Strings with the path to files.
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();
// omitted cmd.setOutputConsumer code
cmd.run(op, image1, image1, image2);
// for files directly:
// cmd.run(op, "1.png", "1.png", "2.png");
Note that the output can still be piped to whatever you want.
Upvotes: 0