Page 1 of 1

What does the -define jpeg:size option concretely do?

Posted: 2017-02-26T12:30:16-07:00
by Johndeer
Hi,

After browsing the FAQ and this forum, I read that the -size option "causes ImageMagick to only store JPEG thumbnails in memory while its generating the montage layout. Without this option, the entire image is temporarily stored in memory until the montage page is generated."

I can't wrap my mind around this notion. Let's say I have a folder with 20k jpeg pictures (each one being a picture with a resolution of 256x256 pixels).

If I were to use "montage -monitor -size 256x256 -geometry 256x256+0+0 -mode concatenate -tile 10x10 '*_*.jpg' finalimage.tiff" to concatenate all my jpegs into a big tiff file, what would concretely happen during the process? Without the size option the finalimage.tiff would be stored in RAM during the whole process (and getting bigger and bigger) whereas if I had used the size option only the jpegs are stored in RAM? I don't really see how it can decrease the memory usage. Could someone explain it to me like I'm five years old? Thank you

Re: What does the -size option concretely do?

Posted: 2017-02-26T12:37:13-07:00
by fmw42
-size specifies the size of some new image that you want to create such as for a gradient or a constant color

Code: Select all

convert -size 100x100 xc:red result.png

Code: Select all

convert -size 100x100 gradient: result.png
For reading JPEG images you need

Code: Select all

-define jpeg:size
See http://www.imagemagick.org/Usage/formats/#jpg_read

See also pseudoimages (that end with :) at
http://www.imagemagick.org/script/formats.php#pseudo

Re: What does the -size option concretely do?

Posted: 2017-02-26T12:52:41-07:00
by Johndeer
fmw42 wrote: 2017-02-26T12:37:13-07:00 -size specifies the size of some new image that you want to create such as for a gradient or a constant color

Code: Select all

convert -size 100x100 xc:red result.png

Code: Select all

convert -size 100x100 gradient: result.png
For reading JPEG images you need

Code: Select all

-define jpeg:size
See http://www.imagemagick.org/Usage/formats/#jpg_read

See also pseudoimages (that end with :) at
http://www.imagemagick.org/script/formats.php#pseudo
Thanks for your reply :)

Oh do you mean the -size option only worked for JPEGs before IM v6.5.6-0? (now replaced by the -define jpeg:size option)

So, if I were to use "montage -monitor -define jpeg:size=256x256 -geometry 256x256+0+0 -mode concatenate -tile 10x10 '*_*.jpg' finalimage.tiff" do I get anything good in terms of memory usage?

Re: What does the -define jpeg:size option concretely do?

Posted: 2017-02-26T17:51:56-07:00
by fmw42
I believe -define is only for convert, but could be wrong. I do not know if it works with montage

Re: What does the -define jpeg:size option concretely do?

Posted: 2017-02-28T08:54:18-07:00
by glennrp
For JPEG, the size option (or jpeg:size option) provides a hint to the JPEG decoder
that it can reduce the size on-the-fly during decoding. This saves memory because
it never has to allocate memory for the full-sized image (assuming the "size" is smaller
than the original dimensions!).

Re: What does the -define jpeg:size option concretely do?

Posted: 2017-03-08T09:27:13-07:00
by Johndeer
glennrp wrote: 2017-02-28T08:54:18-07:00 For JPEG, the size option (or jpeg:size option) provides a hint to the JPEG decoder
that it can reduce the size on-the-fly during decoding. This saves memory because
it never has to allocate memory for the full-sized image (assuming the "size" is smaller
than the original dimensions!).
Hi, thanks for your reply.
I get why using the define jpeg:size option is useless if I specify the same size as the original images' size.
Now what I wonder is if I specify a size smaller than the original's (128x128 for a 256x256 image for example), is it a destructive process? IM will read only half the size of the source images, so the final output image will be missing half the data right?

Re: What does the -define jpeg:size option concretely do?

Posted: 2017-03-08T17:37:33-07:00
by glennrp
I believe that in such cases the JPEG reader will recognize that the hint is too small and use a value that is the next power-of-2 size larger than the target size.