Example #1
0
 /**
  * @throws InvalidArgumentException
  *
  * @param MediaInterface $media
  * @param array          $settings
  *
  * @return Box
  */
 private function computeBox(MediaInterface $media, array $settings)
 {
     if ($this->mode !== ImageInterface::THUMBNAIL_INSET && $this->mode !== ImageInterface::THUMBNAIL_OUTBOUND) {
         throw new InvalidArgumentException('Invalid mode specified');
     }
     $size = $media->getBox();
     $ratios = array($settings['width'] / $size->getWidth(), $settings['height'] / $size->getHeight());
     if ($this->mode === ImageInterface::THUMBNAIL_INSET) {
         $ratio = min($ratios);
     } else {
         $ratio = max($ratios);
     }
     return $size->scale($ratio);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function getHelperProperties(MediaInterface $media, $format, $options = array())
 {
     if ($format == 'reference') {
         $box = $media->getBox();
     } else {
         $resizerFormat = $this->getFormat($format);
         if ($resizerFormat === false) {
             throw new \RuntimeException(sprintf('The image format "%s" is not defined.
                     Is the format registered in your zym_media configuration?', $format));
         }
         $box = $this->resizer->getBox($media, $resizerFormat);
     }
     return array_merge(array('title' => $media->getName(), 'src' => $this->generatePublicUrl($media, $format), 'width' => $box->getWidth(), 'height' => $box->getHeight()), $options);
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function getBox(MediaInterface $media, array $settings)
 {
     $size = $media->getBox();
     if (null != $settings['height']) {
         if ($size->getHeight() > $size->getWidth()) {
             $higher = $size->getHeight();
             $lower = $size->getWidth();
         } else {
             $higher = $size->getWidth();
             $lower = $size->getHeight();
         }
         if ($higher - $lower > 0) {
             return new Box($lower, $lower);
         }
     }
     $settings['height'] = (int) ($settings['width'] * $size->getHeight() / $size->getWidth());
     if ($settings['height'] < $size->getHeight() && $settings['width'] < $size->getWidth()) {
         return new Box($settings['width'], $settings['height']);
     }
     return $size;
 }