Neos\Media\Domain\Service\AssetService::getThumbnailUriAndSizeForAsset PHP Метод

getThumbnailUriAndSizeForAsset() публичный Метод

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
Результат array | null Array with keys "width", "height" and "src" if the thumbnail generation work or null
    public function getThumbnailUriAndSizeForAsset(AssetInterface $asset, ThumbnailConfiguration $configuration, ActionRequest $request = null)
    {
        $thumbnailImage = $this->thumbnailService->getThumbnail($asset, $configuration);
        if (!$thumbnailImage instanceof ImageInterface) {
            return null;
        }
        $resource = $thumbnailImage->getResource();
        if ($thumbnailImage instanceof Thumbnail) {
            $staticResource = $thumbnailImage->getStaticResource();
            if ($configuration->isAsync() === true && $resource === null && $staticResource === null) {
                if ($request === null) {
                    throw new AssetServiceException('Request argument must be provided for async thumbnails.', 1447660835);
                }
                $this->uriBuilder->setRequest($request->getMainRequest());
                $uri = $this->uriBuilder->reset()->setCreateAbsoluteUri(true)->uriFor('thumbnail', array('thumbnail' => $thumbnailImage), 'Thumbnail', 'Neos.Media');
            } else {
                $uri = $this->thumbnailService->getUriForThumbnail($thumbnailImage);
            }
        } else {
            $uri = $this->resourceManager->getPublicPersistentResourceUri($resource);
        }
        return array('width' => $thumbnailImage->getWidth(), 'height' => $thumbnailImage->getHeight(), 'src' => $uri);
    }

Usage Example

 /**
  * 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'];
 }
All Usage Examples Of Neos\Media\Domain\Service\AssetService::getThumbnailUriAndSizeForAsset