Page 1 of 1

Add png compression to identify -verbose

Posted: 2017-08-24T18:27:55-07:00
by fmw42
With regard to viewtopic.php?f=3&t=32526&p=149012#p149099

Would it be possible to add the compression type and/or compression (quality value) for PNG images to the information presented by identify -verbose?

Re: Add png compression to identify -verbose

Posted: 2017-08-26T12:32:41-07:00
by glennrp
Probably not possible and certainly not easy. The PNG format does not explicitly record the "quality", compression method, or filtering method used in compressing the image.

You can make a guess by looking at the filter bytes;

if they are all zero or some other constant N, you can guess that the filtering method was N,

if they are different you can guess that "adaptive filtering" was used.

If they are different but filter methods 3 and 4 weren't used, you can guess that a "adaptive filtering" was used but a "speedy" selection was used.

Zlib records the compression level but only approximately
(fastest, fast, default, and max), according to RFC-1950:

Code: Select all

         FLEVEL (Compression level)
         These flags are available for use by specific compression
         methods.  The "deflate" method (CM = 8) sets these flags as
         follows:

            0 - compressor used fastest algorithm
            1 - compressor used fast algorithm
            2 - compressor used default algorithm
            3 - compressor used maximum compression, slowest algorithm
You cannot rely on the validity of the FLEVEL flag. A compressor can write any of those values there regardless of the compression level actually used.

Re: Add png compression to identify -verbose

Posted: 2017-08-26T12:55:38-07:00
by fmw42
OK. Thanks, Glenn, for the evaluation and explanation. So it appears that one will need to use other tools to check for differences in the same PNG ZIP or ZLIB compression when these kinds of differences occur.

Re: Add png compression to identify -verbose

Posted: 2017-08-27T19:45:21-07:00
by glennrp
Yes, the first tool I usually go to is "pngcheck". If you add enough "v's" it will show you the filter method used for each line

Code: Select all

pngcheck -vvv file.png
(If you add another "v" or two, you'll get every pixel sample, so three is about right for you).
The next tool is "od -c" or "xxd" or my own "pngcrush -n -v" Finally, "identify -verbose". There are others such as "tweakpng".

Re: Add png compression to identify -verbose

Posted: 2017-08-27T20:34:01-07:00
by fmw42
Identify -verbose does not show that information, now, as far as I can tell.

Re: Add png compression to identify -verbose

Posted: 2017-08-28T16:03:17-07:00
by glennrp
fmw42 wrote:
2017-08-27T20:34:01-07:00
Identify -verbose does not show that information, now, as far as I can tell.
Right, it doesn't. As I said, you need to use a large toolbox to get everything. For the particular information you wanted,
"pngcheck -vv file.png" provides it. Note that pngcheck is not libpng-based.

Re: Add png compression to identify -verbose

Posted: 2017-08-28T16:14:08-07:00
by fmw42
Since it requires a large toolbox and is not simple to fold over, then I will drop this request. It seems to be more work than I had anticipated.