示例#1
0
 /**
  * Reverse transform.
  *
  * @param ImageInterface $image
  *
  * @return ImageInterface
  *
  * @throws TransformationFailedException
  */
 public function reverseTransform($image)
 {
     if (null === $image) {
         return null;
     }
     $filename = $image->getFilename();
     if (empty($filename)) {
         return null;
     }
     if ($this->preFilename && $this->preFilename !== $filename) {
         $this->imageManager->remove($image);
     }
     $image = $this->imageManager->findByFilename($filename);
     if (null === $image) {
         throw new TransformationFailedException();
     }
     $image->setTemporary(false);
     return $image;
 }
示例#2
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);
 }