Frage

I'm using ImageMagick to do some image manipulation. I'm trying to stream a file from a service that returns an input stream and do image manipulation on the fly without letting the file hit the HDD.

When I convert the input stream to file using InputStream, OutputStream, FileOutputStream classes, the resulting file size is the same as the file that's stored on the service (initial file size is 9 MB). This is fine. When I run the input stream thru ImageMagick, even though I haven't done any manipulations, the resulting file is way smaller (2 MB). I'm not sure what I'm doing wrong or if ImageMagick is doing something to the file without me knowing. Here's the snippet of my code:

IMOperation op = new IMOperation();
ConvertCmd convert = new ConvertCmd();

InputStream is = s.getFileFromBucket(BUCKET, filename);
op.addImage("-");  // read from stdin
op.addImage(outfile);
Pipe pipeIn = new Pipe (is,null);
convert.setInputProvider(pipeIn);
convert.run(op);
is.close();

So I expected the file to be the same size going out as it was coming in since I haven't done anything to it yet but it's smaller.

Someone had suggested perhaps the service died midway thru while streaming and that's why the file is so small. I don't think this is the case because every test I've run with it going thru ImageMagick, the output file size is the same (2 MB). Also, when I use my viewer to look at the resulting file, it displays the file without problems. Lastly, when I convert the input stream to file, that always results in a file that's 9 MB and displays fine with the viewer.

War es hilfreich?

Lösung

Jpeg is a compressed format, Imagemagick is doing some compressions automatically.

See: http://www.imagemagick.org/Usage/formats/#jpg

"As the JPEG quality gets lower, the size of the image also gets smaller. The default quality setting, when no JPEG quality is set, either by the user, or from the source image format file, is about 92%, which is a very high quality."

Maybe your input Jpeg is lossless -> 100%

EDIT: you can test this by taking the original picture and saving it as jpeg with an arbitrary image processing program by setting the compression rate to 92. Just compare the filesizes afterwards.

Andere Tipps

You should do what romedius suggested (+1).

Additionally, just run

identify -verbose input.stream  > input.txt
identify -verbose output.stream > output.txt

Then compare the two results to see exactly what's different.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top