I'm fairly new to iMagick and have only found very limited documentation on the PHP library. I'm happily resizing images and writing them back to the hard drive, but I'm failing completely to compress the images using JPG for instance.
This is the code I'm using so far:
function scale_image($size = 200,$extension)
{
if(!file_exists(ALBUM_PATH . $this->path . $this->filename . $extension))
{
$im = new imagick(ALBUM_PATH . $this->path . $this->filename);
$width = $im->getImageWidth();
$height = $im->getImageHeight();
if($width > $height)
$im->resizeImage($size, 0, imagick::FILTER_LANCZOS, 1);
else
$im->resizeImage(0 , $size, imagick::FILTER_LANCZOS, 1);
$im->setImageCompression(true);
$im->setCompression(Imagick::COMPRESSION_JPEG);
$im->setCompressionQuality(20);
$im->writeImage(ALBUM_PATH . $this->path . $this->filename . $extension);
$im->clear();
$im->destroy();
}
}
Try this:
$im->setImageCompression(Imagick::COMPRESSION_JPEG);
$im->setImageCompressionQuality(20);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With