getThumbnail() public method

If the maximum width / height is not specified or exceeds the original asset's dimensions, the width / height of the original asset is used.
public getThumbnail ( Neos\Media\Domain\Model\AssetInterface $asset, ThumbnailConfiguration $configuration ) : Neos\Media\Domain\Model\ImageInterface
$asset Neos\Media\Domain\Model\AssetInterface The asset to render a thumbnail for
$configuration Neos\Media\Domain\Model\ThumbnailConfiguration
return Neos\Media\Domain\Model\ImageInterface
 /**
  * @param AssetInterface $image
  * @return void
  */
 public function createThumbnails(AssetInterface $image)
 {
     if ($this->autoCreateThumbnailPresets) {
         foreach ($this->thumbnailService->getPresets() as $preset => $presetConfiguration) {
             $thumbnailConfiguration = $this->thumbnailService->getThumbnailConfigurationForPreset($preset, $this->asyncThumbnails);
             $this->thumbnailService->getThumbnail($image, $thumbnailConfiguration);
         }
     }
 }
 /**
  * Create thumbnails
  *
  * Creates thumbnail images based on the configured thumbnail presets. Optional ``preset`` parameter to only create
  * thumbnails for a specific thumbnail preset configuration.
  *
  * Additionally accepts a ``async`` parameter determining if the created thumbnails are generated when created.
  *
  * @param string $preset Preset name, if not provided thumbnails are created for all presets
  * @param boolean $async Asynchronous generation, if not provided the setting ``Neos.Media.asyncThumbnails`` is used
  * @return void
  */
 public function createThumbnailsCommand($preset = null, $async = null)
 {
     $async = $async !== null ? $async : $this->asyncThumbnails;
     $presets = $preset !== null ? [$preset] : array_keys($this->thumbnailService->getPresets());
     $presetThumbnailConfigurations = [];
     foreach ($presets as $preset) {
         $presetThumbnailConfigurations[] = $this->thumbnailService->getThumbnailConfigurationForPreset($preset, $async);
     }
     $iterator = $this->assetRepository->findAllIterator();
     $imageCount = $this->assetRepository->countAll();
     $this->output->progressStart($imageCount * count($presetThumbnailConfigurations));
     foreach ($this->assetRepository->iterate($iterator) as $image) {
         foreach ($presetThumbnailConfigurations as $presetThumbnailConfiguration) {
             $this->thumbnailService->getThumbnail($image, $presetThumbnailConfiguration);
             $this->persistenceManager->persistAll();
             $this->output->progressAdvance(1);
         }
     }
 }
 /**
  * Calculates the dimensions of the thumbnail to be generated and returns the thumbnail URI.
  * In case of Images this is a thumbnail of the image, in case of other assets an icon representation.
  *
  * @param AssetInterface $asset
  * @param ThumbnailConfiguration $configuration
  * @param ActionRequest $request 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
  * @throws AssetServiceException
  */
 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);
 }
Exemplo n.º 4
0
 /**
  * Returns a thumbnail of this asset
  *
  * If the maximum width / height is not specified or exceeds the original asset's dimensions, the width / height of
  * the original asset is used.
  *
  * @param integer $maximumWidth The thumbnail's maximum width in pixels
  * @param integer $maximumHeight The thumbnail's maximum height in pixels
  * @param string $ratioMode Whether the resulting image should be cropped if both edge's sizes are supplied that would hurt the aspect ratio
  * @param boolean $allowUpScaling Whether the resulting image should be upscaled
  * @return Thumbnail
  * @api
  */
 public function getThumbnail($maximumWidth = null, $maximumHeight = null, $ratioMode = ImageInterface::RATIOMODE_INSET, $allowUpScaling = null)
 {
     $thumbnailConfiguration = new ThumbnailConfiguration(null, $maximumWidth, null, $maximumHeight, $ratioMode === ImageInterface::RATIOMODE_OUTBOUND, $allowUpScaling);
     return $this->thumbnailService->getThumbnail($this, $thumbnailConfiguration);
 }
 /**
  * @param Asset $asset
  * @return array
  */
 protected function getAssetProperties(Asset $asset)
 {
     $assetProperties = ['assetUuid' => $this->persistenceManager->getIdentifierByObject($asset), 'filename' => $asset->getResource()->getFilename()];
     $thumbnail = $this->thumbnailService->getThumbnail($asset, $this->thumbnailService->getThumbnailConfigurationForPreset('Neos.Media.Browser:Thumbnail'));
     if ($thumbnail !== null) {
         $assetProperties['previewImageResourceUri'] = $this->thumbnailService->getUriForThumbnail($thumbnail);
         $assetProperties['previewSize'] = ['w' => $thumbnail->getWidth(), 'h' => $thumbnail->getHeight()];
     }
     return $assetProperties;
 }