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

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Johndeer
Posts: 5
Joined: 2017-02-26T12:09:48-07:00
Authentication code: 1151

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

Post by Johndeer » 2017-02-26T12:30:16-07:00

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
Last edited by Johndeer on 2017-02-26T12:55:27-07:00, edited 1 time in total.

User avatar
fmw42
Posts: 25408
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: What does the -size option concretely do?

Post by fmw42 » 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

Johndeer
Posts: 5
Joined: 2017-02-26T12:09:48-07:00
Authentication code: 1151

Re: What does the -size option concretely do?

Post by Johndeer » 2017-02-26T12:52:41-07:00

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?

User avatar
fmw42
Posts: 25408
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post by fmw42 » 2017-02-26T17:51:56-07:00

I believe -define is only for convert, but could be wrong. I do not know if it works with montage

User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

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

Post by glennrp » 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!).

Johndeer
Posts: 5
Joined: 2017-02-26T12:09:48-07:00
Authentication code: 1151

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

Post by Johndeer » 2017-03-08T09:27:13-07:00

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?

User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

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

Post by glennrp » 2017-03-08T17:37:33-07:00

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.

Post Reply