From 5969ce54e876a92ab3a2981b078330476808a943 Mon Sep 17 00:00:00 2001 From: Cody Jassman Date: Mon, 19 Mar 2018 20:18:48 -0600 Subject: [PATCH] fixed image orientation of photos uploaded via Android when cropped --- src/Upstream.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Upstream.php b/src/Upstream.php index c096c45..6ce5708 100755 --- a/src/Upstream.php +++ b/src/Upstream.php @@ -5,8 +5,8 @@ A simple composer package for Laravel 5 that assists in file uploads and image resizing/cropping. created by Cody Jassman - version 0.6.7 - last updated on November 16, 2017 + version 0.6.8 + last updated on March 19, 2018 ----------------------------------------------------------------------------------------------------------*/ use Illuminate\Support\Facades\File; @@ -367,7 +367,7 @@ public function upload($config = []) case "jpg": case "jpeg": - $image = imagecreatefromjpeg($imagePath); + $image = @imagecreatefromjpeg($imagePath); break; @@ -942,8 +942,24 @@ public function cropImage($config = []) $fileType = ""; if (in_array($originalFileExt, ['jpg', 'jpeg'])) { - $imageOriginal = imagecreatefromjpeg($path.$originalFilename); + $imageOriginal = @imagecreatefromjpeg($path.$originalFilename); $fileType = "jpg"; + + $exif = exif_read_data($path.$originalFilename); + if ($imageOriginal && $exif && isset($exif['Orientation'])) + { + $orientation = $exif['Orientation']; + + if ($orientation == 6 || $orientation == 5) + $imageOriginal = imagerotate($imageOriginal, 270, null); + if ($orientation == 3 || $orientation == 4) + $imageOriginal = imagerotate($imageOriginal, 180, null); + if ($orientation == 8 || $orientation == 7) + $imageOriginal = imagerotate($imageOriginal, 90, null); + + if ($orientation == 5 || $orientation == 4 || $orientation == 7) + imageflip($imageOriginal, IMG_FLIP_HORIZONTAL); + } } else if ($originalFileExt == "gif") {