Reputation: 689
So, I'm testing some of our images with the Imagick PHP library, to see what compression we want to use. But there doesn't seem to be any change to the output file, no matter what I do. This is my basic process:
$original_image = new \Imagick( $image_url );
foreach ( ['original', '92', '80', '60', '40'] as $compression_size )
{
$tester = clone $original_image;
// don't compress the original
if ( 'original' != $compression_size )
{
$tester->setImageCompression(Imagick::COMPRESSION_JPEG);
$tester->setCompressionQuality( (int) $compression_size);
}
$filename: <original base> . "-$compression_size.jpg";
file_put_contents($filename, $tester->getImageBlob() );
$tester = null;
}
The results show that the file sizes between the various compressions don't change, and visually, there is no difference between the original and even the compression = 40 version. What am I doing wrong here?
Upvotes: 1
Views: 1606
Reputation: 15131
From the docs (http://php.net/manual/en/imagick.setcompressionquality.php):
This method only works for new images e.g. those created through Imagick::newPseudoImage. For existing images you should use Imagick::setImageCompressionQuality().
So, replace
$tester->setCompressionQuality( (int) $compression_size);
for
$tester->setImageCompressionQuality( (int) $compression_size);
Upvotes: 9