Inheritance: implements Webiny\Component\Storage\File\FileInterface, use trait Webiny\Component\StdLib\StdObjectTrait, use trait Webiny\Component\EventManager\EventManagerTrait
Esempio n. 1
0
 /**
  * Loads the image and returns an instance of Image class.
  *
  * @param string|File    $image             This can either be image file name that corresponds to File $key parameter,
  *                                          or it can be an instance of Webiny\Component\Storage\File\File.
  * @param string|Storage $storage           This can either be the name of the storage service or it can be an
  *                                          instance of Webiny\Component\Storage\Storage.
  *                                          NOTE: This parameter is not required if you pass the $image as
  *                                          instance of Webiny\Component\Storage\File\File.
  *
  * @return ImageInterface
  */
 public function image($image, $storage = 'local')
 {
     if ($image instanceof File) {
         return ImageLoader::load($image->getContents());
     } else {
         if (!$storage instanceof Storage) {
             $storage = ServiceManager::getInstance()->getService('Storage.' . $storage);
         }
         $file = new File($image, $storage);
         return ImageLoader::load($file->getContents());
     }
 }
Esempio n. 2
0
 /**
  * Creates a new ImageInterface instance from the given image at the provided path.
  *
  * @param File $image Path to an image on the disk.
  *
  * @return \Webiny\Component\Image\ImageInterface
  */
 public function open(File $image)
 {
     return new Image($this->instance->open($image->getAbsolutePath()));
 }
Esempio n. 3
0
 /**
  * Attach a file to your message.
  *
  * @param File $file     File instance
  * @param string    $fileName Optional name that will be set for the attachment.
  * @param string    $type     Optional MIME type of the attachment
  *
  * @return $this
  */
 public function addAttachment(File $file, $fileName = '', $type = 'plain/text')
 {
     $this->message['attachments'][] = ['type' => $type, 'name' => $fileName, 'content' => base64_encode($file->getContents())];
     return $this;
 }
Esempio n. 4
0
 /**
  * Android and Iphone images are sometimes rotated "incorrectly".
  * This method fixes that.
  * Method is called automatically on the `open` method.
  *
  * @param File      $imageFile
  * @param ImageInterface $image
  */
 private static function fixImageOrientation(File $imageFile, ImageInterface $image)
 {
     $format = $image->getFormat();
     // exif data is available only on jpeg and tiff
     // tiff is ignored, because smartphones don't produce tiff images
     if ($format == 'jpg' || $format == 'jpeg') {
         $exifData = exif_read_data($imageFile->getAbsolutePath(), 'IFDO');
         if (isset($exifData['Orientation'])) {
             switch ($exifData['Orientation']) {
                 case 3:
                     $rotation = 180;
                     break;
                 case 6:
                     $rotation = 90;
                     break;
                 case 8:
                     $rotation = -90;
                     break;
                 default:
                     $rotation = 0;
                     break;
             }
             if ($rotation != 0) {
                 $image->rotate($rotation);
             }
         }
     }
 }
Esempio n. 5
0
 /**
  * Writes the record down to the log of the implementing handler
  *
  * @param Record $record
  *
  * @return void
  */
 protected function write(Record $record)
 {
     $this->file->setContents($record->getFormattedRecord(), true);
 }
Esempio n. 6
0
 /**
  * Attach a file to your message.
  *
  * @param File $file     File instance
  * @param string    $fileName Optional name that will be set for the attachment.
  * @param string    $type     Optional MIME type of the attachment
  *
  * @return $this
  */
 public function addAttachment(File $file, $fileName = '', $type = 'plain/text')
 {
     $attachment = new \Swift_Attachment($file->getContents(), $fileName, $type);
     $this->message->attach($attachment);
     return $this;
 }
Esempio n. 7
0
 public function __construct(File $file)
 {
     $this->file = $file;
     $this->storage = $file->getStorage();
     parent::__construct();
 }
Esempio n. 8
0
 /**
  * Attach a file to your message.
  *
  * @param File $file     File instance
  * @param string    $fileName Optional name that will be set for the attachment.
  * @param string    $type     Optional MIME type of the attachment
  *
  * @return $this
  */
 public function addAttachment(File $file, $fileName = '', $type = 'plain/text')
 {
     $this->message->addAttachment($file->getAbsolutePath(), $fileName);
     return $this;
 }