pythonpython-imaging-librarypngquant

File size increase for pngquant output when using PIL


If I compress and image with pngquant, and then read and write out with PIL, I see file size increase significantly (sometimes by up to 2x). Anyone have any tips here? I suspect it may have to do with some PIL flags, but not familiar enough with it.


Solution

  • and then read and write out with PIL, I see file size increase significantly (sometimes by up to 2x)

    Since PNG is lossless and therefore does not introduce artifacts that might be problematic with other encoders, I see only three real possibilities:

    For very small files, non-image chunks might be part of the problem if PIL re-adds some data that pngquant removed. Grab some PNG diagnostic tool capable of dumping list and size of all chunks (PLTE, tEXT etc.) and see where the actual increase takes place (Quick google link).

    zLib could also be to blame (e.g. if memory serves, advpng uses a tricked-up zlib to increase performance), but not with those numbers, unless we're talking small enough files that even a few bytes might be significant.