From cf11b6763bcc08c33d5bdd7d716c06cf7dd045a2 Mon Sep 17 00:00:00 2001 From: Jesper Cockx Date: Tue, 26 Dec 2017 17:11:04 +0100 Subject: [PATCH] Preserve rotation from EXIF data if present --- dist/nano_photos_provider2.json.class.php | 31 ++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/dist/nano_photos_provider2.json.class.php b/dist/nano_photos_provider2.json.class.php index f9b5fd3..2e1af4d 100644 --- a/dist/nano_photos_provider2.json.class.php +++ b/dist/nano_photos_provider2.json.class.php @@ -339,6 +339,28 @@ protected function Compare($a, $b) return ($b) ? +1 : -1; } + function image_fix_orientation(&$image, &$size, $filename) { + $exif = exif_read_data($filename); + + if (!empty($exif['Orientation'])) { + switch ($exif['Orientation']) { + case 3: + $image = imagerotate($image, 180, 0); + break; + + case 6: + $image = imagerotate($image, -90, 0); + list($size[0],$size[1]) = array($size[1],$size[0]); + break; + + case 8: + $image = imagerotate($image, 90, 0); + list($size[0],$size[1]) = array($size[1],$size[0]); + break; + } + } + } + /** * RETRIEVE ONE IMAGE'S DISPLAY URL @@ -387,6 +409,8 @@ protected function GetImageDisplayURL( $baseFolder, $filename ) break; } + $this->image_fix_orientation($orgImage, $size, $baseFolder . $filename); + $width = $size[0]; $height = $size[1]; @@ -488,6 +512,9 @@ protected function GetDominantColorsGIF( $img ) return ''; break; } + + $this->image_fix_orientation($orgImage, $size, $img); + $width = $size[0]; $height = $size[1]; $thumb = imagecreate(3, 3); @@ -526,6 +553,7 @@ protected function GetDominantColor( $img ) return '#000000'; break; } + $this->image_fix_orientation($orgImage, $size, $img); $width = $size[0]; $height = $size[1]; @@ -591,6 +619,7 @@ protected function GenerateThumbnail2($baseFolder, $imagefilename, $thumbnailFil break; } } + $this->image_fix_orientation($orgImage, $size, $baseFolder . $imagefilename); $width = $size[0]; $height = $size[1]; @@ -959,4 +988,4 @@ protected function PrepareData($filename, $kind) } } -?> \ No newline at end of file +?>