I found this post by the late Glenn Randers-Pehrson:
https://www.superuser.com/questions/1124701/is-it-possible-to-retrieve-the-compression-level-from-a-png-image#1125041 wrote:According to the zlib specification (RFC-1950), the zlib datastream within a PNG file contains a two-bit "FLEVEL" flag:
pngcheck checks FLEVEL and reports it like this: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 [levels 0, 1] 1 - compressor used fast algorithm [levels 2-5] 2 - compressor used default algorithm [level 6] 3 - compressor used maximum compression, slowest algorithm [levels 7-9]
While this won't distinguish among all 10 possible compression levels, it could be the basis for creating a libpng png_get_compression_level() function that would at least tell you something.Code: Select all
pngcheck -v rose.png [...] chunk IDAT at offset 0x00073, length 6742 zlib: deflated, 16K window, maximum compression
pngcheck -v test22ps.png → “superfast compression”/“-0.7% compression”:
Code: Select all
File: test22ps.png (3100615 bytes)
chunk IHDR at offset 0x0000c, length 13
1173 x 875 image, 24-bit RGB, non-interlaced
chunk pHYs at offset 0x00025, length 9: 11811x11811 pixels/meter (300 dpi)
chunk iCCP at offset 0x0003a, length 2637
profile name = Photoshop ICC profile, compression method = 0 (deflate)
compressed profile = 2614 bytes
chunk iTXt at offset 0x00a93, length 17356, keyword: XML:com.adobe.xmp
uncompressed, no language tag
no translated keyword, 17335 bytes of UTF-8 text
chunk cHRM at offset 0x04e6b, length 32
White x = 0.31269 y = 0.32899, Red x = 0.63999 y = 0.33
Green x = 0.3 y = 0.6, Blue x = 0.14999 y = 0.05999
chunk IDAT at offset 0x04e97, length 3080476
zlib: deflated, 32K window, superfast compression
chunk IEND at offset 0x2f4fbf, length 0
No errors detected in test22ps.png (7 chunks, -0.7% compression).
Code: Select all
File: test22xn.png (854428 bytes)
chunk IHDR at offset 0x0000c, length 13
1173 x 875 image, 24-bit RGB, non-interlaced
chunk iCCP at offset 0x00025, length 2609
profile name = ICC profile, compression method = 0 (deflate)
compressed profile = 2596 bytes
chunk pHYs at offset 0x00a62, length 9: 11811x11811 pixels/meter (300 dpi)
chunk IDAT at offset 0x00a77, length 8192
zlib: deflated, 32K window, default compression
chunk IDAT at offset 0x02a83, length 8192
chunk IDAT at offset 0x04a8f, length 8192
chunk IDAT at offset 0x06a9b, length 8192
chunk IDAT at offset 0x08aa7, length 8192
chunk IDAT at offset 0x0aab3, length 8192
chunk IDAT at offset 0x0cabf, length 8192
chunk IDAT at offset 0x0eacb, length 8192
chunk IDAT at offset 0x10ad7, length 8192
chunk IDAT at offset 0x12ae3, length 8192
chunk IDAT at offset 0x14aef, length 8192
chunk IDAT at offset 0x16afb, length 8192
chunk IDAT at offset 0x18b07, length 8192
chunk IDAT at offset 0x1ab13, length 8192
chunk IDAT at offset 0x1cb1f, length 8192
chunk IDAT at offset 0x1eb2b, length 8192
chunk IDAT at offset 0x20b37, length 8192
chunk IDAT at offset 0x22b43, length 8192
chunk IDAT at offset 0x24b4f, length 8192
chunk IDAT at offset 0x26b5b, length 8192
chunk IDAT at offset 0x28b67, length 8192
chunk IDAT at offset 0x2ab73, length 8192
chunk IDAT at offset 0x2cb7f, length 8192
chunk IDAT at offset 0x2eb8b, length 8192
chunk IDAT at offset 0x30b97, length 8192
chunk IDAT at offset 0x32ba3, length 8192
chunk IDAT at offset 0x34baf, length 8192
chunk IDAT at offset 0x36bbb, length 8192
chunk IDAT at offset 0x38bc7, length 8192
chunk IDAT at offset 0x3abd3, length 8192
chunk IDAT at offset 0x3cbdf, length 8192
chunk IDAT at offset 0x3ebeb, length 8192
chunk IDAT at offset 0x40bf7, length 8192
chunk IDAT at offset 0x42c03, length 8192
chunk IDAT at offset 0x44c0f, length 8192
chunk IDAT at offset 0x46c1b, length 8192
chunk IDAT at offset 0x48c27, length 8192
chunk IDAT at offset 0x4ac33, length 8192
chunk IDAT at offset 0x4cc3f, length 8192
chunk IDAT at offset 0x4ec4b, length 8192
chunk IDAT at offset 0x50c57, length 8192
chunk IDAT at offset 0x52c63, length 8192
chunk IDAT at offset 0x54c6f, length 8192
chunk IDAT at offset 0x56c7b, length 8192
chunk IDAT at offset 0x58c87, length 8192
chunk IDAT at offset 0x5ac93, length 8192
chunk IDAT at offset 0x5cc9f, length 8192
chunk IDAT at offset 0x5ecab, length 8192
chunk IDAT at offset 0x60cb7, length 8192
chunk IDAT at offset 0x62cc3, length 8192
chunk IDAT at offset 0x64ccf, length 8192
chunk IDAT at offset 0x66cdb, length 8192
chunk IDAT at offset 0x68ce7, length 8192
chunk IDAT at offset 0x6acf3, length 8192
chunk IDAT at offset 0x6ccff, length 8192
chunk IDAT at offset 0x6ed0b, length 8192
chunk IDAT at offset 0x70d17, length 8192
chunk IDAT at offset 0x72d23, length 8192
chunk IDAT at offset 0x74d2f, length 8192
chunk IDAT at offset 0x76d3b, length 8192
chunk IDAT at offset 0x78d47, length 8192
chunk IDAT at offset 0x7ad53, length 8192
chunk IDAT at offset 0x7cd5f, length 8192
chunk IDAT at offset 0x7ed6b, length 8192
chunk IDAT at offset 0x80d77, length 8192
chunk IDAT at offset 0x82d83, length 8192
chunk IDAT at offset 0x84d8f, length 8192
chunk IDAT at offset 0x86d9b, length 8192
chunk IDAT at offset 0x88da7, length 8192
chunk IDAT at offset 0x8adb3, length 8192
chunk IDAT at offset 0x8cdbf, length 8192
chunk IDAT at offset 0x8edcb, length 8192
chunk IDAT at offset 0x90dd7, length 8192
chunk IDAT at offset 0x92de3, length 8192
chunk IDAT at offset 0x94def, length 8192
chunk IDAT at offset 0x96dfb, length 8192
chunk IDAT at offset 0x98e07, length 8192
chunk IDAT at offset 0x9ae13, length 8192
chunk IDAT at offset 0x9ce1f, length 8192
chunk IDAT at offset 0x9ee2b, length 8192
chunk IDAT at offset 0xa0e37, length 8192
chunk IDAT at offset 0xa2e43, length 8192
chunk IDAT at offset 0xa4e4f, length 8192
chunk IDAT at offset 0xa6e5b, length 8192
chunk IDAT at offset 0xa8e67, length 8192
chunk IDAT at offset 0xaae73, length 8192
chunk IDAT at offset 0xace7f, length 8192
chunk IDAT at offset 0xaee8b, length 8192
chunk IDAT at offset 0xb0e97, length 8192
chunk IDAT at offset 0xb2ea3, length 8192
chunk IDAT at offset 0xb4eaf, length 8192
chunk IDAT at offset 0xb6ebb, length 8192
chunk IDAT at offset 0xb8ec7, length 8192
chunk IDAT at offset 0xbaed3, length 8192
chunk IDAT at offset 0xbcedf, length 8192
chunk IDAT at offset 0xbeeeb, length 8192
chunk IDAT at offset 0xc0ef7, length 8192
chunk IDAT at offset 0xc2f03, length 8192
chunk IDAT at offset 0xc4f0f, length 8192
chunk IDAT at offset 0xc6f1b, length 8192
chunk IDAT at offset 0xc8f27, length 8192
chunk IDAT at offset 0xcaf33, length 8192
chunk IDAT at offset 0xccf3f, length 8192
chunk IDAT at offset 0xcef4b, length 6717
chunk IEND at offset 0xd0994, length 0
No errors detected in test22xn.png (108 chunks, 72.3% compression).