Esempio n. 1
0
 /**
  * @param null|int $width
  * @param null|int $height
  * @return string
  */
 private function getResizedImagePath($width, $height)
 {
     if ($width === null && $height === null) {
         $width = $this->image->getWidth();
         $height = $this->image->getHeight();
     } else {
         if ($width === null) {
             $width = $this->image->getWidth();
         } else {
             if ($height === null) {
                 $height = $this->image->getHeight();
             }
         }
     }
     $wRatio = max($this->image->getWidth() / $width, 1);
     $hRatio = max($this->image->getHeight() / $height, 1);
     if (!$this->crop) {
         $wRatio = $hRatio = max($wRatio, $hRatio);
     }
     $width = round($this->image->getWidth() / $wRatio);
     $height = round($this->image->getHeight() / $hRatio);
     $imageSize = $this->fileStorage->createResizedImage($this->image, $width, $height, $this->crop);
     return $this->fileStorage->getWebPath($this->image, $imageSize);
 }
Esempio n. 2
0
 /**
  * Recreate all existing resized versions of the image
  * @param Image $file
  */
 protected function recreateImageSizes(Image $file)
 {
     if (!$file instanceof Image) {
         throw new Exception\RuntimeException('Image entity expected');
     }
     $sizes = $file->getImageSizeCollection();
     if (!$sizes->isEmpty()) {
         foreach ($sizes as $size) {
             $sizeName = $size->getName();
             $filePath = $this->getImagePath($file, $sizeName);
             if (file_exists($filePath)) {
                 $result = unlink($filePath);
                 if (!$result) {
                     throw new Exception\RuntimeException("Could not delete '{$filePath}' from file storage");
                 }
             }
             $this->createResizedImage($file, $size->getTargetWidth(), $size->getTargetHeight(), $size->getCropMode(), $size->getQuality(), true);
         }
     }
 }
 protected function getPrivateImageWebPath(Image $image, $sizeName = null)
 {
     $path = $this->container->getRouter()->generate('media_library_download', array('path' => $image->getFileName()));
     $query = array('inline' => 'inline', 'id' => $image->getId());
     if (!is_null($sizeName)) {
         $imageSize = $image->findImageSize($sizeName);
         if ($imageSize instanceof ImageSize) {
             $query['size'] = $imageSize->getFolderName();
         }
     }
     $queryOutput = http_build_query($query);
     return $path . '?' . $queryOutput . '&';
 }
Esempio n. 4
0
 /**
  * @param Image $image
  * @param int|null $targetWidth
  * @param int|null $targetHeight
  * @param bool $crop
  * @return array
  */
 private function getFullSizeDimensions(Image $image, $targetWidth = null, $targetHeight = null, $crop)
 {
     if ($targetWidth === null && $targetHeight === null) {
         $width = $image->getWidth();
         $height = $image->getHeight();
     } else {
         if ($targetWidth === null) {
             $width = $image->getWidth();
             $height = $targetHeight;
         } else {
             if ($targetHeight === null) {
                 $width = $targetWidth;
                 $height = $image->getHeight();
             }
         }
     }
     $wRatio = max($image->getWidth() / $width, 1);
     $hRatio = max($image->getHeight() / $height, 1);
     if (!$crop) {
         $wRatio = $hRatio = max($wRatio, $hRatio);
     }
     $width = round($image->getWidth() / $wRatio);
     $height = round($image->getHeight() / $hRatio);
     return array($width, $height);
 }