Page 1 of 1
Geometry greater flag (>) not respected when using jpeg:size
Posted: 2013-01-30T06:53:08-07:00
by mtyaka
I'm using -define "jpeg:size=xxx" to limit memory usage when resizing large JPEG images. I noticed that images smaller that the desired output image can get upscaled despite using the ">" geometry flag. For example:
Code: Select all
convert -resize "1500>" -define "jpeg:size=1500" in.jpg out.jpg
where the size of in.jpg is 1250x1250 px, will result in out.jpg with dimensions of 1500x1500 px.
I'm not sure whether this should be considered a bug, since I'm explicitly defining the jpeg:size to equal 1500, but I don't see any other way to limit memory usage when resizing potentially huge images, while still avoiding upscaling.
Re: Geometry greater flag (>) not respected when using jpeg:
Posted: 2013-01-30T07:00:08-07:00
by magick
We're using ImageMagick 6.8.2-1 and getting expected results:
- -> convert -define "jpeg:size=1500" in.jpg -resize "1500>" out.jpg
-> identify out.jpg
out.jpg JPEG 1250x1250 1250x1250+0+0 8-bit sRGB 112KB 0.000u 0:00.009
Re: Geometry greater flag (>) not respected when using jpeg:
Posted: 2013-01-31T03:36:47-07:00
by mtyaka
I tried using ImageMagick 6.8.2-1 compiled against libjpeg 8d using this sample 800x800 image:
http://upload.wikimedia.org/wikipedia/c ... _Vries.jpg
Running the command:
Code: Select all
convert -define "jpeg:size=1000" Koningin_Beatrix_in_Vries.jpg -resize "1000>" out.jpg
produces a 1000x1000 px image for me.
I also tried compiling against libjpeg-turbo instead of standard IJG libjpeg. Running the above command under ImageMagick 6.8.2-1 compiled against libjpeg-turbo produces correct results - the size of out.jpg is 800x800 px.
It looks like IJG libjpeg will upscale the image, while libjpeg-turbo won't. This can be seen running the command:
Code: Select all
convert -define "jpeg:size=5000" Koningin_Beatrix_in_Vries.jpg out.jpg
ImageMagick compiled against IJG libjpeg will produce a 1600x1600 image, while ImageMagick compiled against libjpeg-turbo will produce an image of size 800x800.
I'm running these commands on OS X 10.7.
Re: Geometry greater flag (>) not respected when using jpeg:
Posted: 2013-02-01T16:49:13-07:00
by magick
Older versions of the Independent JPEG Group library have a direct rescaling feature that downsamples only. Newer releases extend the scaling to both downscaling and upscaling so you get different behavior depending on which release level of the JPEG delegate library you use. As such we don't consider this an ImageMagick bug. Instead you need to be aware of the behavior change in libjpeg and construct your ImageMagick command line to account for these differences in behavior.
Re: Geometry greater flag (>) not respected when using jpeg:
Posted: 2013-02-01T19:31:41-07:00
by mtyaka
That makes sense, thank you for looking into it.
Would it be possible to add support for the ">" and "<" flags to jpeg:size? Then one could do:
Code: Select all
convert -define "jpeg:size=1500>" in.jpg -resize "1500>" out.jpg
Which would mean "only use the libjpeg scaling feature if in.jpg is larger than 1500px". That would cover my use case.
Re: Geometry greater flag (>) not respected when using jpeg:
Posted: 2013-02-28T19:10:02-07:00
by anthony
Not posible. the jpeg:size is just a number that is passed to libjpeg.
The alturnative is leave it off, and have the libjpeg return all the pixels, then let IM do the resize from that.
I think it is a pain that libJpeg now does resizeing (up and down) instead of just downsampling. The item was meant to save memory, not actually resize images. Upsizing does not save memory.
Complain to the libjpeg group! If they wanted it to actually resize incoming it should have been a separate option.