コード例 #1
0
ファイル: Uploader.php プロジェクト: ugosansh/component-image
 /**
  * Upload image
  *
  * @param ImageInterface $image   Image entity
  * @param string         $path    Image source path
  * @param array          $options Upload options
  *
  * @return ImageInterface
  */
 public function upload(ImageInterface $image, $path, array $options = [])
 {
     $itemLength = $this->adapter->directoryLength($this->fileSystem->getCurrentDirectory());
     $image = $this->fileSystem->hydrateImageInfo($image, $path);
     $destination = $this->fileSystem->defineImagePath($image, $itemLength);
     $this->adapter->upload($path, $destination, $options);
     $image->setPath($destination);
     return $image;
 }
コード例 #2
0
 /**
  * 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;
 }