Skip to content

Commit

Permalink
fixed image orientation of photos uploaded via Android when cropped
Browse files Browse the repository at this point in the history
  • Loading branch information
Regulus343 committed Mar 20, 2018
1 parent 575df30 commit 5969ce5
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/Upstream.php
Expand Up @@ -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;
Expand Down Expand Up @@ -367,7 +367,7 @@ public function upload($config = [])
case "jpg":
case "jpeg":

$image = imagecreatefromjpeg($imagePath);
$image = @imagecreatefromjpeg($imagePath);

break;

Expand Down Expand Up @@ -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")
{
Expand Down

0 comments on commit 5969ce5

Please sign in to comment.