getThumbnailUriAndSizeForAsset() public method

In case of Images this is a thumbnail of the image, in case of other assets an icon representation.
public getThumbnailUriAndSizeForAsset ( Neos\Media\Domain\Model\AssetInterface $asset, ThumbnailConfiguration $configuration, ActionRequest $request = null ) : array | null
$asset Neos\Media\Domain\Model\AssetInterface
$configuration Neos\Media\Domain\Model\ThumbnailConfiguration
$request Neos\Flow\Mvc\ActionRequest Request argument must be provided for asynchronous thumbnails
return array | null Array with keys "width", "height" and "src" if the thumbnail generation work or null
コード例 #1
0
 /**
  * Renders the path to a thumbnail image, created from a given asset.
  *
  * @param AssetInterface $asset
  * @param integer $width Desired width of the thumbnail
  * @param integer $maximumWidth Desired maximum width of the thumbnail
  * @param integer $height Desired height of the thumbnail
  * @param integer $maximumHeight Desired maximum height of the thumbnail
  * @param boolean $allowCropping Whether the thumbnail should be cropped if the given sizes would hurt the aspect ratio
  * @param boolean $allowUpScaling Whether the resulting thumbnail size might exceed the size of the original asset
  * @param boolean $async Return asynchronous image URI in case the requested image does not exist already
  * @param string $preset Preset used to determine image configuration
  * @return string the relative thumbnail path, to be used as src attribute for <img /> tags
  */
 public function render(AssetInterface $asset = null, $width = null, $maximumWidth = null, $height = null, $maximumHeight = null, $allowCropping = false, $allowUpScaling = false, $async = false, $preset = null)
 {
     if ($preset) {
         $thumbnailConfiguration = $this->thumbnailService->getThumbnailConfigurationForPreset($preset, $async);
     } else {
         $thumbnailConfiguration = new ThumbnailConfiguration($width, $maximumWidth, $height, $maximumHeight, $allowCropping, $allowUpScaling, $async);
     }
     return $this->assetService->getThumbnailUriAndSizeForAsset($asset, $thumbnailConfiguration, $this->controllerContext->getRequest())['src'];
 }
 /**
  * Returns a processed image path
  *
  * @return string
  * @throws \Exception
  */
 public function evaluate()
 {
     $asset = $this->getAsset();
     if (!$asset instanceof AssetInterface) {
         throw new \Exception('No asset given for rendering.', 1415184217);
     }
     $thumbnailConfiguration = new ThumbnailConfiguration($this->getWidth(), $this->getMaximumWidth(), $this->getHeight(), $this->getMaximumHeight(), $this->getAllowCropping(), $this->getAllowUpScaling());
     $thumbnailData = $this->assetService->getThumbnailUriAndSizeForAsset($asset, $thumbnailConfiguration);
     if ($thumbnailData === null) {
         return '';
     }
     return $thumbnailData['src'];
 }
コード例 #3
0
 /**
  * Renders an HTML img tag with a thumbnail image, created from a given asset.
  *
  * @param AssetInterface $asset The asset to be rendered as a thumbnail
  * @param integer $width Desired width of the thumbnail
  * @param integer $maximumWidth Desired maximum width of the thumbnail
  * @param integer $height Desired height of the thumbnail
  * @param integer $maximumHeight Desired maximum height of the thumbnail
  * @param boolean $allowCropping Whether the thumbnail should be cropped if the given sizes would hurt the aspect ratio
  * @param boolean $allowUpScaling Whether the resulting thumbnail size might exceed the size of the original asset
  * @param boolean $async Return asynchronous image URI in case the requested image does not exist already
  * @param string $preset Preset used to determine image configuration
  * @return string an <img...> html tag
  */
 public function render(AssetInterface $asset = null, $width = null, $maximumWidth = null, $height = null, $maximumHeight = null, $allowCropping = false, $allowUpScaling = false, $async = false, $preset = null)
 {
     if ($preset) {
         $thumbnailConfiguration = $this->thumbnailService->getThumbnailConfigurationForPreset($preset, $async);
     } else {
         $thumbnailConfiguration = new ThumbnailConfiguration($width, $maximumWidth, $height, $maximumHeight, $allowCropping, $allowUpScaling, $async);
     }
     $thumbnailData = $this->assetService->getThumbnailUriAndSizeForAsset($asset, $thumbnailConfiguration, $this->controllerContext->getRequest());
     if ($thumbnailData === null) {
         return '';
     }
     $this->tag->addAttributes(array('width' => $thumbnailData['width'], 'height' => $thumbnailData['height'], 'src' => $thumbnailData['src']));
     return $this->tag->render();
 }