Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PNG compression with PHP magickwand

I'm wondering how to compress an PNG image correctly.

The situation is this :

I have a PNG image compressed and color-reduced with Irfanview on Windows. It's about 20KB. When my portal software resizes (using magickwand 1.0.7) it with default values, it's about 63K (!).

Next try was to call MagickSetImageDepth($this->_imageHandler,8), resulting in a filesize of 34K, which is better, but still it's bigger than the (larger in dimension) original file.

None of the documented functions seem to fit to further compress the image.

Any hint would be greatly appreciated !

Greetz, Sosa

like image 304
Claudio030 Avatar asked Nov 14 '22 15:11

Claudio030


1 Answers

PNG compression programs and routines use different techniques. I've found out that many times, an image that's already been compressed (or saved efficiently) cannot be compressed further or even has a higher file size as you are experiencing.

In your case I'd say your images cannot be compressed further, at least using MagickWand. You might just want to leave out that step.

Perhaps optimizing your PNGs before runtime would be a solution. There are many options available in this case. I've had luck with PNGGauntlet. You can run a batch job on PNGGauntlet and it will skip over the files that it would've made larger, if any.

like image 184
Travis Avatar answered Dec 04 '22 22:12

Travis