本文整理汇总了PHP中Sonata\MediaBundle\Model\MediaInterface::getBox方法的典型用法代码示例。如果您正苦于以下问题:PHP MediaInterface::getBox方法的具体用法?PHP MediaInterface::getBox怎么用?PHP MediaInterface::getBox使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sonata\MediaBundle\Model\MediaInterface
的用法示例。
在下文中一共展示了MediaInterface::getBox方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getBox
/**
* {@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);
}
示例2: getHelperProperties
/**
* {@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);
}
示例3: computeBox
/**
* @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);
}
示例4: getHelperProperties
/**
* {@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;
}
示例5: getBox
/**
* {@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;
}
示例6: dummyCompute
public function dummyCompute(MediaInterface $media, array $settings)
{
$size = $media->getBox();
return $this->computeBox($size, $settings);
}
示例7: getBoxHelperProperties
/**
* @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);
}
示例8: getBox
/**
* {@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']);
}