Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What your mom never told you about PNG compression levels
The PNG compression level is that setting in the PNG options that is set by default to 9 and that everyone keeps that way.

But what is its purpose anyway since the compression is lossless? Once decompressed the image is still the same whatever the setting? So why is it an option?

It happens that the PNG compression algorithm is quite CPU-intensive so this setting tells the algorithm how hard it should try to find things to compress. Unlike JPEG where you trade file size for image quality, in the PNG format you trade file size for CPU during export, and on big images it makes quite a difference. So lets see what happens with four different images (16Mpix each except the photo which is 14Mpx):
  • A plain text (8 lines in a text layer with a large font), which is expected to compress very well (PNG is designed to be efficient on computer-generate images)
  • A Simplex noise which is random but with a large proportion of pure black pixels (about 50%)
  • A Plasma noise which is also truly random but is made slightly less random by applying a small median blur to it.
  • A photo of a gorgeous French village.
Each image was exported (without alpha channel) in the 10 levels of compression, measuring the final file size and execution time. Then the results were plotted, using the size relative to the uncompressed version and the relative time to compress:


For instance, in the Simplex case, the final size with compression is about 20% of the uncompressed size, and for level 7 the export took about 5 times longer than the uncompressed export.

These curves make it clear that in all cases, some compression is better than no compression at all.  However, past levels 4-5, there is a very substantial increase in compression time for little or no gain on the file size. In absolute numbers, given that the uncompressed export took a good half second, level 9 is nearly 18 seconds for the photo, when level 6, that produces a file which is less that 3% bigger, takes less that 4 seconds.

Choose wisely Big Grin

Forum Jump: