Пример #1
0
 /**
  * Returns a thumbnail of the given 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 AssetInterface $asset The asset to render a thumbnail for
  * @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
  * @throws \Exception
  */
 public function getThumbnail(AssetInterface $asset, $maximumWidth = NULL, $maximumHeight = NULL, $ratioMode = ImageInterface::RATIOMODE_INSET, $allowUpScaling = NULL)
 {
     $thumbnail = $this->thumbnailRepository->findOneByAssetAndDimensions($asset, $ratioMode, $maximumWidth, $maximumHeight, $allowUpScaling);
     if ($thumbnail === NULL) {
         if (!$asset instanceof ImageInterface) {
             throw new NoThumbnailAvailableException(sprintf('ThumbnailService could not generate a thumbnail for asset of type "%s" because currently only Image assets are supported.', get_class($asset)), 1381493670);
         }
         $thumbnail = new Thumbnail($asset, $maximumWidth, $maximumHeight, $ratioMode, $allowUpScaling);
         $this->thumbnailRepository->add($thumbnail);
         $asset->addThumbnail($thumbnail);
         // Allow thumbnails to be persisted even if this is a "safe" HTTP request:
         $this->persistenceManager->whiteListObject($thumbnail);
         $this->persistenceManager->whiteListObject($thumbnail->getResource());
     }
     return $thumbnail;
 }
 /**
  * Returns a thumbnail of the given 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 AssetInterface $asset The asset to render a thumbnail for
  * @param ThumbnailConfiguration $configuration
  * @return Thumbnail
  * @throws \Exception
  */
 public function getThumbnail(AssetInterface $asset, ThumbnailConfiguration $configuration)
 {
     $thumbnail = $this->thumbnailRepository->findOneByAssetAndThumbnailConfiguration($asset, $configuration);
     if ($thumbnail === null) {
         if (!$asset instanceof ImageInterface) {
             throw new NoThumbnailAvailableException(sprintf('ThumbnailService could not generate a thumbnail for asset of type "%s" because currently only Image assets are supported.', get_class($asset)), 1381493670);
         }
         $thumbnail = new Thumbnail($asset, $configuration);
         $this->thumbnailRepository->add($thumbnail);
         $asset->addThumbnail($thumbnail);
         // Allow thumbnails to be persisted even if this is a "safe" HTTP request:
         $this->persistenceManager->whiteListObject($thumbnail);
         $this->persistenceManager->whiteListObject($thumbnail->getResource());
     }
     return $thumbnail;
 }
 /**
  * Refreshes a thumbnail and persists the thumbnail
  *
  * @param Thumbnail $thumbnail
  * @return void
  */
 public function refreshThumbnail(Thumbnail $thumbnail)
 {
     $thumbnail->refresh();
     $this->persistenceManager->whiteListObject($thumbnail);
     if (!$this->persistenceManager->isNewObject($thumbnail)) {
         $this->thumbnailRepository->update($thumbnail);
     }
 }
 /**
  * Remove all thumbnail objects and resources
  */
 public function clearThumbnailsCommand()
 {
     $thumbnailCount = $this->thumbnailRepository->countAll();
     $this->output->progressStart($thumbnailCount);
     $iterator = $this->thumbnailRepository->findAllIterator();
     foreach ($this->thumbnailRepository->iterate($iterator) as $thumbnail) {
         $this->thumbnailRepository->remove($thumbnail);
         $this->output->progressAdvance(1);
     }
 }
 /**
  * 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;
         }
     }
 }