/** * {@inheritdoc} */ public function getBox(MediaInterface $media, array $settings) { $size = $media->getBox(); $skipBox = false; $constraint = array_key_exists('constraint', $settings) && $settings['constraint'] === false; if ($constraint && $size->getHeight() > $size->getWidth()) { $settings['width'] = $settings['height']; $this->mode = ImageInterface::THUMBNAIL_INSET; $skipBox = true; } $hasWidth = array_key_exists('width', $settings) && $settings['width'] > 0; $hasHeight = array_key_exists('height', $settings) && $settings['height'] > 0; if (!$hasWidth && !$hasHeight) { throw new \RuntimeException(sprintf('Width/Height parameter is missing in context "%s" for provider "%s". Please add at least one parameter.', $media->getContext(), $media->getProviderName())); } if ($hasWidth && $hasHeight && !$skipBox) { return new Box($settings['width'], $settings['height']); } if (!$hasHeight) { $settings['height'] = (int) ($settings['width'] * $size->getHeight() / $size->getWidth()); } if (!$hasWidth) { $settings['width'] = (int) ($settings['height'] * $size->getWidth() / $size->getHeight()); } return $this->computeBox($size, $settings); }
/** * {@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 ``sonata_media`` configuration?', $format)); } $box = $this->resizer->getBox($media, $resizerFormat); } return array_merge(array('alt' => $media->getName(), 'title' => $media->getName(), 'src' => $this->generatePublicUrl($media, $format), 'width' => $box->getWidth(), 'height' => $box->getHeight()), $options); }
/** * @throws InvalidArgumentException * * @param MediaInterface $media * @param array $settings * * @return Box */ protected 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); }
/** * {@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 ``sonata_media`` configuration?', $format)); } $box = $this->resizer->getBox($media, $resizerFormat); } $properties = array_merge(array('poster' => $this->generatePublicUrl($media, $this->getFormatName($media, 'wide_big')), 'alt' => $media->getName(), 'title' => $media->getName(), 'src' => $this->generatePublicUrl($media, $format), 'width' => $box->getWidth(), 'height' => $box->getHeight(), 'type' => $media->getContentType(), 'controls' => true, 'autoplay' => true, 'loop' => false, 'width' => '"100%"', 'height' => 100, 'waveColor' => 'red', 'progressColor' => 'blue', 'cursorColor' => 'green'), $options); return $properties; }
/** * {@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; }
public function dummyCompute(MediaInterface $media, array $settings) { $size = $media->getBox(); return $this->computeBox($size, $settings); }
/** * @param \Sonata\MediaBundle\Model\MediaInterface $media * @param string $format * @param array $options * * @return \Imagine\Image\Box */ protected function getBoxHelperProperties(MediaInterface $media, $format, $options = array()) { if ($format == 'reference') { return $media->getBox(); } if (isset($options['width']) || isset($options['height'])) { $settings = array('width' => isset($options['width']) ? $options['width'] : null, 'height' => isset($options['height']) ? $options['height'] : null); } else { $settings = $this->getFormat($format); } return $this->resizer->getBox($media, $settings); }
/** * {@inheritdoc} */ public function getBox(MediaInterface $media, array $settings) { $size = $media->getBox(); if ($settings['width'] === null && $settings['height'] === null) { $settings['width'] = $size->getWidth(); $settings['height'] = $size->getHeight(); } if ($settings['height'] === null) { $settings['height'] = (int) ($settings['width'] * $size->getHeight() / $size->getWidth()); } if ($settings['width'] === null) { $settings['width'] = (int) ($settings['height'] * $size->getWidth() / $size->getHeight()); } return new Box($settings['width'], $settings['height']); }