Example #1
0
 /**
  * create thumbnail from existing image with max sizes
  * 
  * @param link $im - ImageMagick object
  * @param string $targetFilePath
  * @param int $maxX
  * @param int $maxY 
  */
 public function createThumbnail($im, $sourceInfo, $targetFilePath, $width, $height, $save_dimensions = false)
 {
     if ($sourceInfo) {
         if ($width && $height) {
             if ($save_dimensions) {
                 $ratio_orig = $sourceInfo[0] / $sourceInfo[1];
                 if ($width / $height > $ratio_orig) {
                     $width = round($height * $ratio_orig);
                 } else {
                     $height = round($width / $ratio_orig);
                 }
             }
             if ($sourceInfo[0] < $width) {
                 $width = $sourceInfo[0];
                 $height = $sourceInfo[1];
             }
             $width && $height ? $im->cropThumbnailImage($width, $height) : false;
         }
         $im->setImageCompression(imagick::COMPRESSION_JPEG);
         $im->setImageCompressionQuality(95);
         $im->stripImage();
         $result = $im->writeImage($targetFilePath);
         $im->destroy();
         return $result;
     }
 }