/** * Create image child * * @param ImageInterface $parent * @param integer $width * @param integer $height * @param integer $crop * * @return ImageInterface */ protected function createChild(ImageInterface $parent, $width, $height, $crop = null) { $source = $this->fileSystem->getAbsolutePath($parent->getPath()); $image = $this->fileSystem->hydrateImageInfo($this->createEntity(), $source); $image->setParent($parent); $image->setTitle($parent->getTitle()); $image->setSource($parent->getSource()); $image->setPath($this->fileSystem->defineImagePath($image)); $destination = $this->fileSystem->getAbsolutePath($image->getPath()); $destinationDir = substr($image->getPath(), 0, strrpos($image->getPath(), '/')); $this->fileSystem->createDirectory($destinationDir); $this->resizer->setSource($source); if (!is_null($crop)) { $this->resizer->setRatio($crop); } if ($this->resizer->resize($destination, $width, $height)) { $image = $this->fileSystem->hydrateImageInfo($image, $destination); $this->save($image); return $image; } return false; }
/** * get source image * * @param ImageInterface $image * * @return string */ public function getImageSource(ImageInterface $image) { $path = $this->getAbsolutePath($image->getPath()); if (!is_file($path)) { throw new IOException(sprintf('Not found image source "%s"', $image->getId())); } return file_get_contents($path); }