diff options
author | Andreas Unterkircher <unki@netshadow.at> | 2007-07-06 06:13:12 +0000 |
---|---|---|
committer | Andreas Unterkircher <unki@netshadow.at> | 2007-07-06 06:13:12 +0000 |
commit | 64f41bc1539ec51b909817df8b71094e7ceb7724 (patch) | |
tree | 16035ffe6a8542d160d5af768c3d6844db922615 | |
parent | 0f50117ed5b287ce472e288c3b3eb7be2783b064 (diff) |
issue22, vertical images should now get resized correctly also if the rotation is specified via EXIF orientation.
git-svn-id: file:///var/lib/svn/phpfspot/trunk@165 fa6a889d-dae6-447d-9e79-4ba9a3039384
-rw-r--r-- | phpfspot.class.php | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/phpfspot.class.php b/phpfspot.class.php index 204c8a7..818aca6 100644 --- a/phpfspot.class.php +++ b/phpfspot.class.php @@ -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) { |