PHP + Imagick - PNG Compression

How to efficiently compress PNG? In my case, the images are small grayscale images with transparency.

I am currently playing with this:

// ... $im->setImageFormat('png'); $im->setImageColorspace(\Imagick::COLORSPACE_GRAY); $im->setImageCompression(\Imagick::COMPRESSION_LZW); $im->setImageCompressionQuality(9); $im->stripImage(); $im->writeImage($url_t); 

Since Imagick does not offer COMPRESSION_PNG , I tried LZW, but there are almost no changes in file size (usually it is even bigger than before).

If I open the image in GIMP and just save it, the file size will be significantly reduced (for example, 11.341 B → 3.763 B or 11.057 B → 3.538).

What is the correct way to save compressed PNG using Imagick?

+6
source share
2 answers

Take a look at the first part of this answer:

It explains the syntax of the value + ImageMagick -quality for PNG.

+3
source

I'm definitely not sure if this is the right way to save PNG, but my way is:

 $im->setImageCompression(\Imagick::COMPRESSION_UNDEFINED); $im->setImageCompressionQuality(0); 

This gives me excellent image quality and file size very similar to the PS6 saved by Save for Web. Sometimes even smaller!

+1
source

Source: https://habr.com/ru/post/897572/


All Articles