Exemplo n.º 1
0
 private function resize_imagick($src, $width, $height, $quality, $preserveExif)
 {
     try {
         $img = new imagick($src);
         if (strtoupper($img->getImageFormat()) === 'JPEG') {
             $img->setImageCompression(imagick::COMPRESSION_JPEG);
             $img->setImageCompressionQuality($quality);
             if (!$preserveExif) {
                 try {
                     $orientation = $img->getImageOrientation();
                 } catch (ImagickException $e) {
                     $orientation = 0;
                 }
                 $img->stripImage();
                 if ($orientation) {
                     $img->setImageOrientation($orientation);
                 }
             }
         }
         $img->resizeImage($width, $height, Imagick::FILTER_LANCZOS, true);
         $result = $img->writeImage($src);
         $img->clear();
         $img->destroy();
         return $result ? true : false;
     } catch (Exception $e) {
         return false;
     }
 }
Exemplo n.º 2
-1
 public static function resize($orig_file_path, $settings, $target_file_path)
 {
     $quality = 95;
     $crop = $settings['crop_method'];
     $current_width = $settings['width'];
     $current_height = $settings['height'];
     $target_width = min($current_width, $settings['width_requested']);
     $target_height = min($current_height, $settings['height_requested']);
     if ($crop) {
         $x_ratio = $target_width / $current_width;
         $y_ratio = $target_height / $current_height;
         $ratio = min($x_ratio, $y_ratio);
         $use_x_ratio = $x_ratio == $ratio;
         $new_width = $use_x_ratio ? $target_width : floor($current_width * $ratio);
         $new_height = !$use_x_ratio ? $target_height : floor($current_height * $ratio);
     } else {
         $new_width = $target_width;
         $new_height = $target_height;
     }
     $im = new imagick($orig_file_path);
     $im->cropThumbnailImage($new_width, $new_height);
     $im->setImageCompression(imagick::COMPRESSION_JPEG);
     $im->setImageCompressionQuality($quality);
     $im->stripImage();
     $result = $im->writeImage($target_file_path);
     $im->destroy();
     return array($new_width, $new_height, $target_width, $target_height);
 }