4

I have a couple of JPEGs. Is there a way to find out which compression level was used when encoding them? That is, were they encoded at level 60 or 90?


The reason I'm asking is because I have a site where I use compressed images, which was compressed in a particular program. Now I want to compress the reset of my images in the same program and at the same level so they will kind of look "as bad" as the other ones :)

  • what is the practical reason for the question? What do you want to achieve in the end? i am asking because maybe there is another solution – aaaaaa Mar 25 '17 at 3:07
  • @aaaaaa I added some more info to my question regarding the reason I'm wondering. Maybe you have a good suggestion for that scenario? – PetaspeedBeaver Mar 25 '17 at 20:37
9

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.

4

You can, sort of. ImageMagicks' identify command can show a estiamte

identify -verbose image.jpeg

will produce (a lot of) information about the image.

One of the lines will be something like:

Quality: 84

If that command shows too much, and you only need the quality, you may pipe it with grep:

identify -verbose image.jpeg | grep Quality

(Stolen and expanded from "How to find the jpg quality", at superuser.com)

(edited, to include that it is not EXIF data but a guesstimate, and to say "go and read the other nice, and probably better, answer" :-)

  • 1
    This does assume the metadata has not been stripped, such as is the case with many images displayed on the web. – Michael C Mar 24 '17 at 8:36
  • 1
    @MichaelClark You are right, but the answer is not correct. ImageMagicks does not use the EXIF data to produce the quality level, but counts the number of quantization tables. See my answer for a longer explanation why not even that is a particularly clever approach. – jarnbjo Mar 24 '17 at 11:37
  • This is still helpful in some cases, though - if used carefully. File size might be simpler but if images have also been batch processed for resolution you might need to take both into account. – Chris H Mar 25 '17 at 8:24
  • @ChrisH Depends on what you are looking for. Both file size and the 'quality' index determined by ImageMagick are purely technical values with no reliable dependency on the perceived quality of the image. – jarnbjo Mar 25 '17 at 11:02
  • @jarnbjo I'm thinking of cases where images have been compressed by an unknown process and possibly resized. For example if the same image was downloaded from twitter and Facebook the files wouldn't be identical even assuming identical uploads - which is better (for a particular purpose)? For a one-off, inspection is simple, but not for a batch. – Chris H Mar 25 '17 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.