Beispiel #1
0
 /**
  * Paste another image into this one a the specified dimension.
  *
  * @param ImageInterface $image   Image to paste.
  * @param int            $offsetX Offset on x axis.
  * @param int            $offsetY Offset on y axis
  *
  * @return $this
  */
 public function paste(ImageInterface $image, $offsetX = 0, $offsetY = 0)
 {
     $point = new Point($offsetX, $offsetY);
     $this->image->paste($image->getInstance(), $point);
     return $this;
 }
Beispiel #2
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);
             }
         }
     }
 }