예제 #1
0
 /**
  * Get image path.
  *
  * @param string $path
  *
  * @return string
  */
 private function getImagePath($path)
 {
     if ($path && file_exists($this->filesystem->getRootDir() . $path)) {
         return $path;
     }
     return $this->noImagePath;
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function resize($imagePath, array $size, $mode, $force = false)
 {
     $cacheKey = $this->getCacheKey($size, $mode);
     $filename = basename($imagePath);
     if (false === $force && $this->imageCache->contains($filename, $cacheKey)) {
         return $this->imageCache->getRelativePath($filename, $cacheKey);
     }
     $cacheAbsolutePath = $this->imageCache->getAbsolutePath($filename, $cacheKey);
     $imagine = new Imagine();
     $imagineImage = $imagine->open($this->filesystem->getRootDir() . $imagePath);
     $imageSize = array($imagineImage->getSize()->getWidth(), $imagineImage->getSize()->getHeight());
     $boxSize = $this->resizeHelper->getBoxSize($imageSize, $size);
     $box = $this->getBox($boxSize[0], $boxSize[1]);
     if (ImageResizerInterface::INSET === $mode) {
         $imageSizeInBox = $this->resizeHelper->getImageSizeInBox($imageSize, $boxSize);
         $imagineImage->resize($this->getBox($imageSizeInBox[0], $imageSizeInBox[1]));
         $palette = new RGB();
         $box = $imagine->create($box, $palette->color($this->color, $this->alpha));
         $imagineImage = $box->paste($imagineImage, $this->getPointInBox($imageSizeInBox, $boxSize));
     } else {
         $imagineImage = $imagineImage->thumbnail($box);
     }
     $this->filesystem->mkdir(dirname($cacheAbsolutePath));
     $imagineImage->save($cacheAbsolutePath, ImageOptionHelper::getOption($filename));
     return $this->imageCache->getRelativePath($filename, $cacheKey);
 }
예제 #3
0
 /**
  * @return Image
  */
 private function createImage()
 {
     $image = new Image();
     $image->setFilename('silvestra.png');
     $image->setOriginalPath($this->filesystem->getRelativeFilePath($image->getFilename()));
     $this->symfonyFilesystem->copy(dirname(__FILE__) . '/../../Fixtures/silvestra.png', $this->filesystem->getActualFileDir($image->getFilename()) . '/' . $image->getFilename());
     return $image;
 }
예제 #4
0
 /**
  * Create image.
  *
  * @param UploadedFile $uploadedImage
  *
  * @return ImageInterface
  */
 public function createImage(UploadedFile $uploadedImage)
 {
     $image = $this->imageManager->create();
     $filename = $this->getUniqueFilename($uploadedImage);
     $image->setFilename($filename);
     $image->setMimeType($uploadedImage->getClientMimeType());
     $image->setOrderNr(1);
     $image->setOriginalPath($this->filesystem->getRelativeFilePath($filename));
     $image->setPath($image->getOriginalPath());
     $image->setSize($uploadedImage->getClientSize());
     $image->setTemporary(true);
     $this->imageManager->add($image);
     $fileDir = $this->filesystem->getActualFileDir($filename);
     $uploadedImage->move($fileDir, $image->getFilename());
     return $image;
 }
예제 #5
0
 /**
  * {@inheritdoc}
  */
 public function crop(ImageInterface $image, array $coordinates)
 {
     $absolutePath = $this->filesystem->getRootDir() . $image->getOriginalPath();
     if (false === file_exists($absolutePath)) {
         throw new NotFoundImageException(sprintf('Not found image in %s', $absolutePath));
     }
     $this->filesystem->mkdir($this->filesystem->getActualFileDir($image->getFilename(), Filesystem::CROPPER_SUB_DIR));
     $imagine = new Imagine();
     $imagine->open($absolutePath)->crop($this->getStartPoint($coordinates['x1'], $coordinates['y1']), $this->getBox($coordinates))->save($this->filesystem->getAbsoluteFilePath($image->getFilename(), Filesystem::CROPPER_SUB_DIR), ImageOptionHelper::getOption($image->getFilename()));
     return $this->filesystem->getRelativeFilePath($image->getFilename(), Filesystem::CROPPER_SUB_DIR);
 }
예제 #6
0
 public function testGetAbsoluteFilePath()
 {
     $this->assertEquals($this->getMediaRootDir() . '/uploader/s/i/l/v/e/silvestra.png', $this->filesystem->getAbsoluteFilePath('silvestra.png'));
 }
예제 #7
0
 /**
  * {@inheritdoc}
  */
 public function getRelativePath($filename, $key)
 {
     $parts = array(Media::NAME, Filesystem::CACHE_SUB_DIR, $this->filesystem->getFileDirPrefix($filename), trim($key, DIRECTORY_SEPARATOR), $filename);
     return DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $parts);
 }