Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Setting png compression level in Imagerby vr (Curate) |
on May 13, 2018 at 11:45 UTC ( [id://1214428]=note: print w/replies, xml ) | Need Help?? |
Well, if execution time can be sacrificed... As you already found, Imager (through libpng) uses zlib's level 6, which is "good enough", because zlib's max (9) delivers compression only marginally better. But we can beat this "level 9" using more robust algorithm.
The test subject is this image. Note the change history (disregard early versions, they are of low quality) -- last guy who uploaded final copy was, perhaps, using same Zopfli compressor. I'm lazy to handle IDAT chunk(s) by hand, so there's Image::PNG::Rewriter DIY used. To kick-start compressor (passed as sub to constructor), it looks like some "is_dirty" flag needs to be set, or otherwise original IDAT is output as it was. Hence, the "no_op" line above, which filters scan-lines with the same values as original. I didn't investigate if Zopfli parameters can deliver (a) better compression or (b) faster execution with almost the same compression. Heh, BTW, we can check if libpng is smart enough to find out itself, which filter to use with each scan-line:
BTW, all of the above is assuming, that you are working with true-color 24 bpp images, which cannot be (losslessly) converted to 8 bpp palletized PNG images.
In Section
Seekers of Perl Wisdom
|
|