/** * @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; }
/** * 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); }
/** * 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); }
/** * 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 ``TYPO3.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); } } }
/** * @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); }
/** * 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); }