/**
  * Generate thumbnail and redirect to resource URI
  *
  * @param Thumbnail $thumbnail
  * @return void
  */
 public function thumbnailAction(Thumbnail $thumbnail)
 {
     if ($thumbnail->getResource() === null && $thumbnail->getStaticResource() === null) {
         $this->thumbnailService->refreshThumbnail($thumbnail);
     }
     $this->redirectToUri($this->thumbnailService->getUriForThumbnail($thumbnail), 0, 302);
 }
 /**
  * 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'];
 }
 /**
  * @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);
         }
     }
 }
 /**
  * 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
  * @return array with keys "width", "height" and "src"
  */
 public function getThumbnailUriAndSizeForAsset(AssetInterface $asset, ThumbnailConfiguration $configuration)
 {
     if ($asset instanceof ImageInterface) {
         $thumbnailImage = $this->thumbnailService->getThumbnail($asset, $configuration);
         $thumbnailData = array('width' => $thumbnailImage->getWidth(), 'height' => $thumbnailImage->getHeight(), 'src' => $this->resourceManager->getPublicPersistentResourceUri($thumbnailImage->getResource()));
     } else {
         $thumbnailData = $this->getAssetThumbnailImage($asset, $configuration->getWidth() ?: $configuration->getMaximumWidth(), $configuration->getHeight() ?: $configuration->getMaximumHeight());
     }
     return $thumbnailData;
 }
Exemple #5
0
 /**
  * Calculates the dimensions of the thumbnail to be generated and returns the thumbnail image if the new dimensions
  * differ from the specified image dimensions, otherwise the original image is returned.
  *
  * @param ImageInterface $image
  * @param integer $maximumWidth
  * @param integer $maximumHeight
  * @param boolean $allowCropping
  * @param boolean $allowUpScaling
  * @return ImageInterface
  */
 protected function getImageThumbnailImage(ImageInterface $image, $maximumWidth = NULL, $maximumHeight = NULL, $allowCropping = NULL, $allowUpScaling = NULL)
 {
     $ratioMode = $allowCropping ? ImageInterface::RATIOMODE_OUTBOUND : ImageInterface::RATIOMODE_INSET;
     if ($allowUpScaling === FALSE) {
         $maximumWidth = $maximumWidth > $image->getWidth() ? $image->getWidth() : $maximumWidth;
         $maximumHeight = $maximumHeight > $image->getHeight() ? $image->getHeight() : $maximumHeight;
     }
     if ($maximumWidth === $image->getWidth() && $maximumHeight === $image->getHeight()) {
         return $image;
     }
     return $this->thumbnailService->getThumbnail($image, $maximumWidth, $maximumHeight, $ratioMode, $allowUpScaling);
 }
 /**
  * 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();
 }
 /**
  * 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', 'TYPO3.Media');
         } else {
             $uri = $this->thumbnailService->getUriForThumbnail($thumbnailImage);
         }
     } else {
         $uri = $this->resourceManager->getPublicPersistentResourceUri($resource);
     }
     return array('width' => $thumbnailImage->getWidth(), 'height' => $thumbnailImage->getHeight(), 'src' => $uri);
 }
 /**
  * Render ungenerated thumbnails
  *
  * Loops over ungenerated thumbnails and renders them. Optional ``limit`` parameter to limit the amount of
  * thumbnails to be rendered to avoid memory exhaustion.
  *
  * @param integer $limit Limit the amount of thumbnails to be rendered to avoid memory exhaustion
  * @return void
  */
 public function renderThumbnailsCommand($limit = null)
 {
     $thumbnailCount = $this->thumbnailRepository->countUngenerated();
     $iterator = $this->thumbnailRepository->findUngeneratedIterator();
     $this->output->progressStart($limit !== null && $thumbnailCount > $limit ? $limit : $thumbnailCount);
     $iteration = 0;
     foreach ($this->thumbnailRepository->iterate($iterator) as $thumbnail) {
         if ($thumbnail->getResource() === null) {
             $this->thumbnailService->refreshThumbnail($thumbnail);
             $this->persistenceManager->persistAll();
         }
         $this->output->progressAdvance(1);
         $iteration++;
         if ($iteration === $limit) {
             break;
         }
     }
 }
 /**
  * @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('TYPO3.Neos:Thumbnail'));
     if ($thumbnail !== null) {
         $assetProperties['previewImageResourceUri'] = $this->thumbnailService->getUriForThumbnail($thumbnail);
         $assetProperties['previewSize'] = ['w' => $thumbnail->getWidth(), 'h' => $thumbnail->getHeight()];
     }
     return $assetProperties;
 }
 /**
  * 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);
 }
Exemple #11
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)
 {
     return $this->thumbnailService->getThumbnail($this, $maximumWidth, $maximumHeight, $ratioMode, $allowUpScaling);
 }