I'm using im4java to convert image. The following program crashes with stack trace: Caused by: org.im4java.core.CommandException: convert: insufficient image data in file /tmp/magick-254901G7YJ9qaMQv5' @ error/jpeg.c/ReadJPEGImage/1154.
Looks like it's generating a temp file. Running the same command directly on ImageMagick command lines gives me correct results.
I'm running ImageMagick-6.9.10-61 and im4java 1.4.0
I wonder if anyone has any insights.
IMOperation op = new IMOperation();
op.addImage("-");
op.addImage("jpg:-");
op.quality(0.85);
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
// image is of type MultipartFile
Pipe pipeIn = new Pipe(image.getInputStream(), null);
Pipe pipeOut = new Pipe(null, outputStream);
convertCmd.setInputProvider(pipeIn);
convertCmd.setOutputConsumer(pipeOut);
convertCmd.run(op);
return outputStream.toByteArray();
} catch (Exception e) {
//
}