Esempio n. 1
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);
 }
Esempio n. 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);
 }