From 65680c50746d3d1063b52e13a29fe57d87387b71 Mon Sep 17 00:00:00 2001 From: Matthias Glienke Date: Mon, 8 Sep 2014 11:23:21 +0200 Subject: [PATCH] Adding support for exif data "orientation" --- class.Images.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/class.Images.php b/class.Images.php index e05e8e7..bc500ae 100755 --- a/class.Images.php +++ b/class.Images.php @@ -205,6 +205,26 @@ public function resize($max_width, $max_height, $method="fit", $cropAreaLeftRigh //Let's get it on, create image! list($image_create_func, $image_save_func) = $this->getFunctionNames(); + + // check if it is a jpg and if there are exif data about Orientation (e.g. on uploading an image from smartphone) + if( $this->getMimeType() == "image/jpg" || $this->getMimeType() == "image/jpeg") + { + $exif = exif_read_data($this->image); + if(!empty($exif['Orientation'])) { + switch($exif['Orientation']) { + case 8: + $this->rotate(90, $jpgQuality); + break; + case 3: + $this->rotate(180, $jpgQuality); + break; + case 6: + $this->rotate(-90, $jpgQuality); + break; + } + } + } + $imageC = ImageCreateTrueColor($newImage_width, $newImage_height); $newImage = $image_create_func($this->image);