コード例 #1
0
ファイル: Image.php プロジェクト: jacksun101/streams-platform
 /**
  * Set the image.
  *
  * @param  $image
  * @return $this
  */
 public function setImage($image)
 {
     if ($image instanceof Presenter) {
         $image = $image->getObject();
     }
     if ($image instanceof FieldType) {
         $image = $image->getValue();
     }
     // Replace path prefixes.
     if (is_string($image) && str_contains($image, '::')) {
         $image = $this->paths->realPath($image);
         $this->setExtension(pathinfo($image, PATHINFO_EXTENSION));
         $size = getimagesize($image);
         $this->setWidth(array_get($size, 0));
         $this->setHeight(array_get($size, 1));
     }
     if (is_string($image) && str_is('*://*', $image) && !starts_with($image, ['http', 'https'])) {
         $this->setExtension(pathinfo($image, PATHINFO_EXTENSION));
     }
     if ($image instanceof FileInterface) {
         /* @var FileInterface $image */
         $this->setExtension($image->getExtension());
         $this->setWidth($image->getWidth());
         $this->setHeight($image->getHeight());
     }
     if ($image instanceof FilePresenter) {
         /* @var FilePresenter|FileInterface $image */
         $image = $image->getObject();
         $this->setExtension($image->getExtension());
         $this->setWidth($image->getWidth());
         $this->setHeight($image->getHeight());
     }
     $this->image = $image;
     return $this;
 }