summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Unterkircher <unki@netshadow.at>2007-07-01 15:43:15 +0000
committerAndreas Unterkircher <unki@netshadow.at>2007-07-01 15:43:15 +0000
commita19902be5b020202a23b037d43528c85514a3fc0 (patch)
tree83a78eb4acc3ff499a4b459a65dbd8278bd93f40
parent4c5aa67169b34a02bd7c3b482f178cb93f6700f9 (diff)
issue22, vertical images are now getting resized correctly
git-svn-id: file:///var/lib/svn/phpfspot/trunk@157 fa6a889d-dae6-447d-9e79-4ba9a3039384
-rw-r--r--phpfspot.class.php30
1 files changed, 23 insertions, 7 deletions
diff --git a/phpfspot.class.php b/phpfspot.class.php
index ca5f7b4..0960243 100644
--- a/phpfspot.class.php
+++ b/phpfspot.class.php
@@ -638,23 +638,39 @@ class PHPFSPOT {
}
/* grabs the height and width */
- $new_w = imagesx($src_img);
- $new_h = imagesy($src_img);
+ $cur_width = imagesx($src_img);
+ $cur_height = imagesy($src_img);
// If requested width is more then the actual image width,
// do not generate a thumbnail
- if($width >= $new_w) {
+ if($width >= $cur_width) {
imagedestroy($src_img);
return true;
}
/* calculates aspect ratio */
- $aspect_ratio = $new_h / $new_w;
+ $aspect_ratio = $cur_height / $cur_width;
/* sets new size */
- $new_w = $width;
- $new_h = abs($new_w * $aspect_ratio);
+ if($aspect_ratio < 1) {
+ $new_w = $width;
+ $new_h = abs($new_w * $aspect_ratio);
+ } else {
+ /* 'virtually' rotate the image and calculate it's ratio */
+ $tmp_w = $cur_height;
+ $tmp_h = $cur_width;
+ /* now get the ratio from the 'rotated' image */
+ $tmp_ratio = $tmp_h/$tmp_w;
+ /* now calculate the new dimensions */
+ $tmp_w = $width;
+ $tmp_h = abs($tmp_w * $tmp_ratio);
+
+ // now that we know, how high they photo should be, if it
+ // gets rotated, use this high to scale the image
+ $new_h = $tmp_h;
+ $new_w = abs($new_h / $aspect_ratio);
+ }
/* creates new image of that size */
$dst_img = imagecreatetruecolor($new_w, $new_h);
@@ -674,7 +690,7 @@ class PHPFSPOT {
}
if($rotate) {
- print "(ROTATE)";
+ $this->_debug("(ROTATE)");
$dst_img = $this->rotateImage($dst_img, $rotate);
}