/** * {@inheritdoc} */ public function createVariation(ImageFormat $output_format, $quality, ImageDimensions $dimensions = null, ImageCropDimensions $crop_dimensions = null) { try { $img = new InterventionImage($this->data); } catch (\Intervention\Image\Exception\InvalidImageDataStringException $e) { throw new BadImageException('Bad image data', 0, $e); } catch (\Intervention\Image\Exception\ImageNotFoundException $e) { throw new BadImageException('Not an image', 0, $e); } if ($dimensions) { if ($dimensions->getGrab()) { $img->grab($dimensions->getWidth(), $dimensions->getHeight()); } else { $img->resize($dimensions->getWidth(), $dimensions->getHeight(), $dimensions->getMaintainRatio(), $dimensions->canUpscale()); } } return $img->encode($output_format->key(), $quality); }
/** * {@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(); }