3

Can I know whether a PNG file was compressed and how (at least, whether it was a lossless compression) in Windows? When I open the standard file properties dialog from the Windows Explorer, I see no properties regarding this.

8

PNG is always compressed by DEFLATE algorithm, as mandated by PNG specification. This is same algorithm used by zip compressor, among others.

There are no lossy compression algorithms for PNGs. PNG is always loseless.

Disclaimer: There are methods of "optimizing" PNG size by decreasing quality (color depth) of an image before saving it as PNG. This has nothing to do with PNG itself and cannot be reliably detected neither in PNG nor the original file.

  • Many image edit apps allow you to specify some additional parameters when saving your work as PNG. For instance, in paint.net we see the 'Dithering Level' option. As for the ZIP compression, we can also specify the compression level using such archivers as 7-Zip. What about that? Is there a way to read this info from the PNG header if it is possible at all? – TecMan May 26 '15 at 10:34
  • 2
    @TecMan "Dithering Level" is an option of reducing the image to 8bit color, not saving PNG. Note that it's same for every 8-bit save, not only for PNGs. It's completely unrelated to file operation, showing it there is merely convenience. In other editors you do "convert->8bit" first and then "save as". As for choosing zip compression level, I haven't thought about that. But (as it's loseless) it doesn't affect the image, only affects memory usage of compressing and decompressing (in 7-zip you can see estimate). – Agent_L May 26 '15 at 10:46
  • If we talk about paint.net, "Dithering Level" and "Bit Depth" are two different options we can set while saving an image as PNG. And we can have different effects and images of different sizes playing with each option. – TecMan May 26 '15 at 15:30
  • 1
    @TecMan: When you set the compression level using 7-Zip or any other archiver, can it be retrieved from a ZIP file? Similarly it doesn't seem to be stored in the PNG header either. As for dithering, it has to do with reducing banding in the image. It's not directly related to PNG compression in any way. The point is, why do you want to know these details in the first place? – Karan May 26 '15 at 18:26
  • 1
    @TecMan: I can't think of any instance where knowing the compression level would make a difference when looking at screenshots, but maybe it's important to you for some reason. Regardless, you have your answer. – Karan May 27 '15 at 13:50
2

Estimating compression ratio of any image file is actually pretty simple. You have to know the width, height and bit depth of the image. To calculate how much data would be needed by uncompressed raw image data you have to do this simple thing: raw data size = image width * image heigth * (bits per pixel / 8). Then just divide raw data size by your PNG's file size by and you have the estimated compression ratio (not exact value because of the headers, etc.). For example 640x480x32 image would need 640 * 480 * (32 / 8) which is 1 273 800 bytes. Now lets assume your PNG has 200kB. You divide (200 * 1024) / 1273800. That gives you a compression ratio of about 0.16.

And remember about one fact. Sometimes 24 bit images are actually stored as 32 bit value. So you have to take that into account.

  • It is a manual and a bit rough calculation. The question was about an automatic way to know that. Anyway, +1 to your answer. – TecMan May 26 '15 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.