简体   繁体   中英

How do I compress a .png with Imagick in PHP?

I'm converting .jpg and .gif images to .png using PHP's Imagick library.

I've successfully converted these images to .png using this:

$image = new Imagick( $file_path );
$image->setImageFormat( 'png' );
$image->writeImage( $file_path );

However, I have been unable to compress the .pngs or control their final size at all. I've tried using the following line before $image->setImageFormat() and a few other variations with no success:

$img->setImageCompressionQuality( 95 ); 

If .png compression with Imagick is lacking, then what other utilities should I use to compress these files?

This manual may help.

I installed OptiPNG and it works fine.

After a lengthy battle, I was unable to get IMagick to compress png's properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM