From 10578e1b06f9b3b206c95975b4b51421a662af01 Mon Sep 17 00:00:00 2001 From: Sascha Nos Date: Sat, 2 Jan 2016 20:21:10 +0100 Subject: [PATCH 1/3] use orientation data from exif when creating new image --- src/ImageResize.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/ImageResize.php b/src/ImageResize.php index 27dd6e2..d1b2866 100644 --- a/src/ImageResize.php +++ b/src/ImageResize.php @@ -80,7 +80,7 @@ public function __construct($filename) break; case IMAGETYPE_JPEG: - $this->source_image = imagecreatefromjpeg($filename); + $this->source_image = $this->imageCreateJpegfromExif($filename); break; case IMAGETYPE_PNG: @@ -94,6 +94,32 @@ public function __construct($filename) return $this->resize($this->getSourceWidth(), $this->getSourceHeight()); } + + // http://stackoverflow.com/a/28819866 + public function imageCreateJpegfromExif($filename){ + $img = imagecreatefromjpeg($filename); + $exif = exif_read_data($filename); + + if (!$exif || !isset($exif['Orientation'])){ + return $img; + } + + $orientation = $exif['Orientation']; + + if ($orientation === 6 || $orientation === 5){ + $img = imagerotate($img, 270, null); + } else if ($orientation === 3 || $orientation === 4){ + $img = imagerotate($img, 180, null); + } else if ($orientation === 8 || $orientation === 7){ + $img = imagerotate($img, 90, null); + } + + if ($orientation === 5 || $orientation === 4 || $orientation === 7){ + imageflip($img, IMG_FLIP_HORIZONTAL); + } + + return $img; + } /** * Saves new image From e2a35011e648268d567dfb6da404630e6b33cdac Mon Sep 17 00:00:00 2001 From: Sascha Nos Date: Sat, 2 Jan 2016 20:27:49 +0100 Subject: [PATCH 2/3] rename project for local using --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 20acd05..7c24823 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "eventviva/php-image-resize", + "name": "saschanos/php-image-resize", "description": "PHP class to re-size and scale images", "keywords": ["php", "image", "resize","scale"], "type": "library", From 4180bc1fd37da5136f7507d8b4c8488bd4d2702a Mon Sep 17 00:00:00 2001 From: Sascha Nos Date: Sat, 2 Jan 2016 20:29:31 +0100 Subject: [PATCH 3/3] rename project for local using --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7c24823..20acd05 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "saschanos/php-image-resize", + "name": "eventviva/php-image-resize", "description": "PHP class to re-size and scale images", "keywords": ["php", "image", "resize","scale"], "type": "library",