Optimal JPEG thumbnail dimensions

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
Bilge
Posts: 9
Joined: 2012-09-05T12:53:29-07:00
Authentication code: 67789

Optimal JPEG thumbnail dimensions

Post by Bilge »

Hi,

I only know a little about the JPEG format but I thought that JPEGs are subdivided into "blocks" at a low level. Is it therefore the case that if you want to generate as small a thumbnail image as possible you should select image dimensions that are divisible by this block size? If so what should the dimensions ideally be divisible by?
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: Optimal JPEG thumbnail dimensions

Post by NicolasRobidoux »

With the most commonly used parameters, width and height should be multiples of 16 (they can be different without harm) with the default chroma subsampling, 8 if you turn off chroma subsampling.
Bilge
Posts: 9
Joined: 2012-09-05T12:53:29-07:00
Authentication code: 67789

Re: Optimal JPEG thumbnail dimensions

Post by Bilge »

Why might someone turn off chroma subsampling?
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: Optimal JPEG thumbnail dimensions

Post by NicolasRobidoux »

1) If your image is very small and its dimensions are not multiples of 16, you may not gain much compression given the quality decrease.
2) Subsampling adds artifacts which are sometimes better avoided by not subsampling but instead decreasing the quality setting of the chroma channels: http://www.wfu.edu/~matthews/misc/jpg_v ... maSub.html.
The full story on optimizing JPEG is complicated business which I don't want to go into. Partly because this is how I make my living.
Bilge
Posts: 9
Joined: 2012-09-05T12:53:29-07:00
Authentication code: 67789

Re: Optimal JPEG thumbnail dimensions

Post by Bilge »

Oh, OK. That's cool, I guess. I wasn't trying to take away your livelihood.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: Optimal JPEG thumbnail dimensions

Post by NicolasRobidoux »

@Bilge: No worries. Really.
I just did not want to get back "But if blah blah blah, then isn't it that blah blah blah..." Because what I said is full of caveats, and I did not feel like writing a long manual.
Bilge
Posts: 9
Joined: 2012-09-05T12:53:29-07:00
Authentication code: 67789

Re: Optimal JPEG thumbnail dimensions

Post by Bilge »

How do I disable chroma subsampling with ImageMagick?
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: Optimal JPEG thumbnail dimensions

Post by NicolasRobidoux »

Bilge
Posts: 9
Joined: 2012-09-05T12:53:29-07:00
Authentication code: 67789

Re: Optimal JPEG thumbnail dimensions

Post by Bilge »

NicolasRobidoux wrote:Use 1x1.
I actually tried that but I got the same result as if I hadn't specified the sampling factor option at all so I thought it must be invalid. The only value that I tried which changed the output was 2x1 which resulted in a file size reduction.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: Optimal JPEG thumbnail dimensions

Post by NicolasRobidoux »

I vaguely remember requesting that the default be switched to no chroma subsampling. Apparently it is. I believe that with older IM 2x1 is the default.
2x1 is standard chroma subsampling.
Generally, 2x1 is a very good size reduction/visual quality trade off.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: Optimal JPEG thumbnail dimensions

Post by NicolasRobidoux »

Yes, I'm pretty sure that I made that request, on the basis that users should get something very very good when the JPEG quality setting is set to a high value, and you simply don't get that with 2x1, no matter the quality setting. If you set the quality to 95, it generally makes no sense to use 2x1.
Post Reply