Page 1 of 1

How does getImageCompressionQuality work?

Posted: 2015-04-06T12:19:25-07:00
by Imagition
Hi there,

I have been using ImageMagick (Imagick) for a couple of days now and it amazes me every day. Now I got to a point in my application where I have to rely on values that come from analyzing an image using $image->getImageCompressionQuality(). It seems to work quite well but I'm curious how it is possible to obtain the compression quality from a file. The images I have to process come from very different sources (exported with editing programs, unedited, somewhere from the internet...) so I need to know how reliable the information really is. I have only tested jpg files as jpg is the most popular format being used in this project.

Therefore my question ist: how does getImageCompressionQuality really work (with jpg)? Is it reading out metadata or does it use quantization tables (like this: http://www.hackerfactor.com/src/jpegquality.c) or a complete different approach?

Thanks in advance.

EDIT: I'm using the PHP api.

Re: How does getImageCompressionQuality work?

Posted: 2015-04-06T13:12:47-07:00
by glennrp
For JPEG, it examines the quantization tables and compares them with those used by the IJG libjpeg compressor. See the function JPEGSetImageQuality() in coders/jpeg.c. It's not the same as jpegquaiity.c (it predates jpegquality.c by several years; it was added to ImageMagick version 5.5.1).

Re: How does getImageCompressionQuality work?

Posted: 2015-04-06T18:32:47-07:00
by Imagition
Thanks for the fast and spot on reply! So the values should be pretty reliable, that corresponds with what I have experienced so far. Sometimes it's way off when analyzing jpgs that had been saved with absurdly low quality settings (0 in Photoshop e.g.) but these extreme cases don't really bother me.