コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function createVariation(ImageFormat $output_format, $quality, ImageDimensions $dimensions = null, ImageCropDimensions $crop_dimensions = null)
 {
     $src = $this->getTempFile($this->data);
     $img = new \Imagick();
     $img->setResolution($this->resolution, $this->resolution);
     $img->readImage($src);
     $img->setIteratorIndex(0);
     // Flatten images here helps the encoder to get rid of the black background
     // that appears on encoded image files.
     $img = $img->flattenImages();
     $img->setImageFormat((string) $output_format->value());
     $img->setImageCompressionQuality($quality);
     if (null !== $crop_dimensions) {
         $img->cropImage($crop_dimensions->getWidth(), $crop_dimensions->getHeight(), $crop_dimensions->getX(), $crop_dimensions->getY());
     }
     if (null !== $dimensions) {
         $img->resizeImage($dimensions->getWidth() ?: 0, $dimensions->getHeight() ?: 0, $this->filter, 1, false);
     }
     return $img->getImageBlob();
 }