Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP+Imagick - PNG Compression

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

Currently I'm 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);

As Imagick doesn't offer COMPRESSION_PNG, I've tried LZW but there's almost no change in the filesize (usually it's even bigger than before).

If I open the image in GIMP and simply save it, the filesize gets drastically reduced (e.g. 11,341 B --> 3,763 B or 11,057 B --> 3,538).

What is the correct way of saving a compressed PNG with Imagick?

like image 440
Czechnology Avatar asked Sep 18 '11 16:09

Czechnology


1 Answers

Have a look at the first part of this answer:

  • Convert multipage PDF to PNG and back (Linux)

It explains the meaning + syntax of ImageMagick's -quality setting for PNGs.

like image 76
Kurt Pfeifle Avatar answered Oct 18 '22 02:10

Kurt Pfeifle