'How can I know the jpeg quality of the read image using graphicsmagick

When I read a jpeg image using Magick::readImages(...) function. How can I know the estimated jpeg quality of the image? I know how to set the quality when I wanna write the image, but it is not relevant to the quality of the original image, so for example: when I read a jpeg image that its quality is 80% and I write it using 90% quality I will get a bigger image than the original one, since the 90% is not 90% out of the original 80%. How can I know the jpeg quality of the read image?



Solution 1:[1]

It is neither impossible nor difficult with GraphicsMagick (or with ImageMagick). Type

gm convert -log %e -debug coder in.jpg junk.ppm

and look in the output for the line

Quality: nn

if the image was created by Independent JPEG Group software or

Quality: nn (approximate)

otherwise.

You can also use

gm identify -verbose in.png

and look at the

Quality: nn

line; however, this doesn't distinguish between exact and approximate qualities.

Solution 2:[2]

It's possible but difficult. The code has to examine the image just like people do. Here's a paper on the subject http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.4.4621&rep=rep1&type=pdf

Solution 3:[3]

If you want to read the JPEG metadata, you can use the following in command-line:

gm identify -format "%[JPEG-Quality]" your-photo.jpg

In C++, it might be using IdentifyImage : https://imagemagick.org/api/MagickCore/identify_8c.html#a91079e7db05c1bad53b2dbb2b01f41ba

That said, as other users said, it's just a number generated by the software that produced the image. As a matter of fact, I can see that GM 1.4 returns nothing on a JPEG without profile information, but GM 1.3.35 does a wild guess with jpeg.c/EstimateJPEGQuality/932/Coder (that returns 100%).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 BenMorel
Solution 3