How to find the JPG quality?

16

4

When I save a JPG file with GIMP, I can adjust the quality I save it at, from 0-100 (I use 89). It seems like I've used an app to see what this number was on saved file but if I did I can't for the life of me figure out what it was. Any suggestions as to what to use?

Nathaniel

Posted 2009-10-29T19:46:29.750

Reputation: 3 966

2

Just to make sure that it is known: the quality setting of different applications is not comparable, in general: http://www.faqs.org/faqs/jpeg-faq/part1/section-5.html. Both GIMP and ImageMagick should use the IJG quality scale, though.

– Michael Schumacher – 2015-09-29T12:36:50.367

Answers

22

Once saved, you cannot tell the quality anymore.

(Setting the quality while saving just tells the software how much loss you find acceptable, but once saved: what's lost is lost. You'd need a human to say if something looks nice.)

Hmmm, I guess I was wrong. I still think the above is correct, but ImageMagick's identify proves me wrong?

identify -verbose myimage.jpg

Image: myimage.jpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Class: DirectClass
  Geometry: 358x240+0+0
  Resolution: 300x300
  [...]
  Compression: JPEG
  Quality: 90
  Orientation: Undefined
  [...]

I don't know how the image in my test was saved, but it does not have any EXIF data. Could the quality still be stored in the image?

Arjan

Posted 2009-10-29T19:46:29.750

Reputation: 29 084

1ImageMagick is doing something different. It gives an estimate, rather than reading what your original software did. Your original, now-crossed-out, answer is really more correct. See @sleske's answer. – mattdm – 2017-03-24T13:14:51.067

Can't you experiment converting to different qualities? I find it hard to believe, unless ImageMagick stores some private data in the jpg (so this might not work with other packages). – harrymc – 2009-10-29T20:37:32.533

Interesting. I'll wait to see how this pans out. – Nathaniel – 2009-10-29T21:10:28.050

1+1 Yes imagemagick works. I can repeatedly change the jpeg quality and use identify to see the change. This works if I use convert (another imagemagick untility) or another tool like MS Photo Editor. – DaveParillo – 2009-10-29T22:20:35.617

28

To add to Arjan's answer:

ImageMagick's identify appears to actually look inside the JPEG image to guess the quality setting used to encode it.

ImageMagick's source code (cheer for free software :-)) contains the lines:

/*
  Determine the JPEG compression quality from the quantization tables.
*/
sum=0;
for (i=0; i < NUM_QUANT_TBLS; i++)
{
  if (jpeg_info.quant_tbl_ptrs[i] != NULL)
    for (j=0; j < DCTSIZE2; j++)
      sum+=jpeg_info.quant_tbl_ptrs[i]->quantval[j];

(coders/jpeg.c, line 843ff. in my recent version of ImageMagick's source code).

I don't know enough about JPEG to really understand, but it appears to do something like described in this article:

Determine the JPEG quality factor by using Visual C# .NET (link dead as of Januar 2018; copy on archive.org from 2015)

So yes, identify can actually determine the quality setting of a JPEG just from the compressed file alone (though the result may not always be completely accurate).

sleske

Posted 2009-10-29T19:46:29.750

Reputation: 19 887

@Nathaniel, can you please select this answer as being the accepted one, instead of mine? Thanks! (I cannot delete mine as long as it's accepted.) – Arjan – 2017-03-24T14:22:15.167

It is searching for the JPEG quantization table that best accounts for how the compressed bitstream looks. – jbarlow – 2018-04-19T04:05:01.887

Constants (jpeglib.h): NUM_QUANT_TBLS = 4. DCTSIZE2 = 64. quantval[i] just gets the number at given position. – user136036 – 2020-02-25T23:58:41.977

1Whoa. Very nice of you to check the source code. Cool. – Nathaniel – 2010-01-04T20:17:38.037

6

As Arjan metioned identify -verbose myimage.jpg will do it. As imagemagick is a CLI tool, it may be useful for scripting. The approach identify -verbose myimage.jpg | grep ... is preety slow. I recommend using IM like this

identify -format '%Q' myimage.jpg

It is massively faster.

ManuelSchneid3r

Posted 2009-10-29T19:46:29.750

Reputation: 503

3

JPEGsnoop is a nice alternative to ImageMagick's identify. The download is quite small and is available in portable format.

After processing a jpg, you will find the "Approx quality factor" under the DQT marker.

idmadj

Posted 2009-10-29T19:46:29.750

Reputation: 133

1

Picasa 3 has the properties pane which shows the jpeg quality but it is an abandonware at the moment. Picasa 3 Dick Masterson

Uğur Gümüşhan

Posted 2009-10-29T19:46:29.750

Reputation: 1 216

http://www.filehorse.com/download-picasa/ – Iman Abidi – 2017-08-02T17:02:35.063

1

With ImageMagick++ library it's easy:

Image magick_image( pathname );
size_t compressionFactor = magick_image.quality(); // 0..100

Valeriy Van

Posted 2009-10-29T19:46:29.750

Reputation: 111