Ejemplo n.º 1
0
 /**
  * {@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);
 }