Can you determine the original JPEG compression/quality setting from a JPEG file?

Asked 3/23/2017

4 views

2 answers

0

I have several JPEG images and want new images to match their existing compression and visual quality. Is there a reliable way to tell what JPEG compression or quality setting was originally used (for example, whether it was saved at 60 or 90)? If not, is there at least a practical way to estimate it so I can save future images to look roughly the same?

Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0

Photography Stack Exchange contributor

9y ago

2 Answers

19

No, you can not and it does not make sense to do so, since there is no ubiquitous definition of the JPEG compression level. The actual result when saving a JPEG with compression level 60 in one software can differ significantly from what another software produces when set to level 60.

If you use ImageMagick as suggested by Rolazaro Azeveires, it will indeed print a quality-number, but this number is not based on EXIF data. ImageMagick calculates its own quality-index based on the number of quantization tables in the image file and this number may again differ from the quality level you actually set when saving the image.

For example, if you have a structurally simple image, the simplest being a single-coloured tile, and you save it at level 100 with a software using a perceived quality index, the software can save the image essentially lossless with only a small number of quantization tables. Analyzing the file later with ImageMagick is likely to give you a very low quality level, since ImageMagick only sees a few quantization tables and does not realize that actually only a small number of quantization tables was necessary to save the file at a high quality setting.

Here are for example the quality reported by ImageMagick for some different options when saving an image from Photoshop:

Photoshop                 ImageMagick identify -verbose
save for web q=1/100         Quality: 55
save for web q=80/100        Quality: 94
save for web q=100/100       Quality: 99
save image q=1/12            Quality: 81
save image q=6/12            Quality: 92
save image q=12/12           Quality: 99

As you can see, even within one software, two different functions 'save image' and 'save for web and devices' are both using different quality level scales and neither match the quality level reported by ImageMagick.

Addition: Since Chris H tries to argue that the quality level as reported by ImageMagick can be useful in some cases, I will show some examples why that is not the case. The only reasonable way to judge the quality of a JPEG file is to look at it and not to rely on some magic number procuded by a software tool.

Let's first look at this JPEG file. Yes, the quality is not exceptionally good, there are some visible artifacts and ImageMagick reports a quality of 62 while the file size is 17.426 bytes:

enter image description here

Let us assume that we have the same image from a different source and for this file, ImageMagick reports a quality of 99 and the file size is 21.470 bytes:

enter image description here

It should IMHO be very obvious that neither file size nor ImageMagick's quality level are suitable to judge the true quality of an image file.

Originally by user10009. Source · Licensed CC BY-SA 4.0

user10009

9y ago

0

AI Answer

Generated from our catalog & community — verify before relying on it.

Not reliably. A JPEG file does not usually preserve the original app’s exact “quality” or “compression level” setting in any standard, universal way. A setting like 60 or 90 is software-specific, so “quality 60” in one program may not match “quality 60” in another.

What you can do is estimate. Tools like ImageMagick can inspect the JPEG and report a guessed quality value, for example with identify -verbose image.jpg or identify -format "%Q\n" image.jpg. But that number is not EXIF metadata and not the original saved setting; it’s an approximation derived from the JPEG’s quantization tables.

So:

  • You generally cannot recover the exact original save setting.
  • Even if you get an estimated number, it may not correspond to the same number in your software.
  • For matching older images, the practical approach is to use the same software if possible, compare visually, and use an estimate as a starting point rather than a definitive answer.

UniqueBot

AI

9y ago

Your Answer