/**
  * {@inheritDoc}
  */
 public function process(MediaInterface $media, VariantInterface $variant, \SplFileInfo $source = NULL)
 {
     $options = $variant->getOptions();
     $result = $source;
     list($originalWidth, $originalHeight) = getimagesize($source->getPathName());
     $width = $originalWidth;
     $height = $originalHeight;
     if (is_array($options) && !empty($options)) {
         if ($this->imagine == NULL) {
             throw new ProviderProcessException(sprintf('Cannot process image "%s": Imagine library not installed or misconfigured', $media), $this, $media, $variant);
         }
         $options = $this->processOptions($options, $variant->getName(), $media->getContext());
         $destFile = sprintf('%s%s-temp-%s.%s', $this->tempDir, date('Y-m-d-h-i-s'), $source->getBasename('.' . $source->getExtension()), $options['format']);
         /**
          * @var \Imagine\Image\ImageInterface $image
          */
         $image = $this->imagine->open($source);
         if ($options['enlarge'] === TRUE || $originalWidth >= $options['width'] && $originalHeight >= $options['height']) {
             $width = $options['width'];
             $height = $options['height'];
             if ($options['resize'] == 'proportional') {
                 //calculate missing dimension
                 if ($width === NULL) {
                     $width = round($originalWidth * $height / $originalHeight);
                 } elseif ($height === NULL) {
                     $height = round($width * $originalHeight / $originalWidth);
                 }
             }
             $box = new \Imagine\Image\Box($width, $height);
             if ($options['resize'] == 'proportional' || $options['resize'] == 'stretch') {
                 $image->resize($box);
             } elseif ($options['resize'] == 'crop') {
                 $image = $image->thumbnail($box, \Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND);
             }
         }
         $image->save($destFile, array('quality' => $options['quality']));
         $this->addTempFile($destFile);
         $result = new \SplFileInfo($destFile);
     }
     //set variant metadata
     $variant->setMetaValue('size', $result->getSize());
     $variant->setMetaValue('width', $width);
     $variant->setMetaValue('height', $height);
     return $result;
 }
 /**
  * {@inheritDoc}
  */
 public function process(MediaInterface $media, VariantInterface $variant, \SplFileInfo $source = NULL)
 {
     $variant->setMetaValue('size', $source->getSize());
     return $source;
 }