views:

287

answers:

1

Hi All,

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(); 
 }
}

Any help would be greatly appreciated.

Many Thanks

Rob

A: 

setImageCompression seems to expect an integer as parameter rather than a boolean (see : http://www.php.net/manual/en/function.imagick-setimagecompression.php).

I think image compression may work if you disable this line :

$im->setImageCompression(true);
Benjamin Delichère