issue22, vertical images should now get resized correctly also if the rotation is...
authorAndreas Unterkircher <unki@netshadow.at>
Fri, 6 Jul 2007 06:13:12 +0000 (06:13 +0000)
committerAndreas Unterkircher <unki@netshadow.at>
Fri, 6 Jul 2007 06:13:12 +0000 (06:13 +0000)
git-svn-id: file:///var/lib/svn/phpfspot/trunk@165 fa6a889d-dae6-447d-9e79-4ba9a3039384

phpfspot.class.php

index 204c8a7374f4c687ba88ebb2e96d149943f98c7e..818aca658730bf4e0468a9735711abc612ebafc7 100644 (file)
@@ -617,21 +617,21 @@ class PHPFSPOT {
 
       switch($meta['Orientation']) {
 
-         case 1:
+         case 1: /* top, left */
             $rotate = 0; $flip = false; break;
-         case 2:
+         case 2: /* top, right */
             $rotate = 0; $flip = true; break;
-         case 3:
+         case 3: /* bottom, left */
             $rotate = 180; $flip = false; break;
-         case 4:
+         case 4: /* bottom, right */
             $rotate = 180; $flip = true; break;
-         case 5:
+         case 5: /* left side, top */
             $rotate = 90; $flip = true; break;
-         case 6:
+         case 6: /* right side, top */
             $rotate = 90; $flip = false; break;
-         case 7:
+         case 7: /* left side, bottom */
             $rotate = 270; $flip = true; break;
-         case 8:
+         case 8: /* right side, bottom */
             $rotate = 270; $flip = false; break;
       }
 
@@ -654,6 +654,14 @@ class PHPFSPOT {
          return true;
       }
 
+      // If the image will be rotate because EXIF orientation said so
+      // 'virtually rotate' the image for further calculations
+      if($rotate == 90 || $rotate == 270) {
+         $tmp = $cur_width;
+         $cur_width = $cur_height;
+         $cur_height = $tmp;
+      }
+
       /* calculates aspect ratio */
       $aspect_ratio = $cur_height / $cur_width;
 
@@ -675,6 +683,14 @@ class PHPFSPOT {
          // gets rotated, use this high to scale the image
          $new_h = $tmp_h;
          $new_w = abs($new_h / $aspect_ratio);
+
+         // If the image will be rotate because EXIF orientation said so
+         // now 'virtually rotate' back the image for the image manipulation
+         if($rotate == 90 || $rotate == 270) {
+            $tmp = $new_w;
+            $new_w = $new_h;
+            $new_h = $tmp;
+         }
       }
 
       /* creates new image of that size */
@@ -683,7 +699,7 @@ class PHPFSPOT {
       imagefill($dst_img, 0, 0, ImageColorAllocate($dst_img, 255, 255, 255));
 
       /* copies resized portion of original image into new image */
-      imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
+      imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, imagesx($src_img), imagesy($src_img));
 
       /* needs the image to be flipped horizontal? */
       if($flip) {