Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What your mom never told you about PNG compression levels
#1
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 than 3% bigger, takes less than 4 seconds.

Choose wisely Big Grin
Reply
#2
(11-06-2023, 12:59 PM)Ofnuts Wrote: The PNG compression level is that setting in the PNG options that is set by default to 9 and that everyone keeps that way.

Thanks for this post. The relevant graphs for art work are plasma and photo, probably more photo. I would say the optimal setting is where time intersects file size. For photo that is about 7.5. Because size is decreasing slowly lower would be OK. Probably compression level 6 over default 9 is preferable.
I could use this because I process over 1k PNGs at a time and I can reduce compression.
Reply
#3
Wow.. Seeing that compression 1 does most of the job, and then after the gain is so small compared to the time that is kind of deceptive.

Thank you very much Ofnuts for these tests, those are very useful, and changed my perception
Patrice
Reply


Forum Jump: