How does getImageCompressionQuality work?

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
Imagition
Posts: 2
Joined: 2015-04-01T08:20:39-07:00
Authentication code: 6789

How does getImageCompressionQuality work?

Post 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.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: How does getImageCompressionQuality work?

Post 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).
Imagition
Posts: 2
Joined: 2015-04-01T08:20:39-07:00
Authentication code: 6789

Re: How does getImageCompressionQuality work?

Post 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.
Post Reply