Add png compression to identify -verbose

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Add png compression to identify -verbose

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

Re: Add png compression to identify -verbose

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Add png compression to identify -verbose

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

Re: Add png compression to identify -verbose

Post 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".
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Add png compression to identify -verbose

Post by fmw42 »

Identify -verbose does not show that information, now, as far as I can tell.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Add png compression to identify -verbose

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Add png compression to identify -verbose

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