From 0693afd6b74988b1527fe771d64d3c5e14cef84a Mon Sep 17 00:00:00 2001 From: friendica Date: Sat, 29 Sep 2012 05:20:29 -0700 Subject: [PATCH] only constrain horizontal image dimension for scaling very tall photos --- include/Photo.php | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/include/Photo.php b/include/Photo.php index 00c424c64..42b54b14e 100644 --- a/include/Photo.php +++ b/include/Photo.php @@ -227,7 +227,18 @@ class Photo { return FALSE; if($width > $max && $height > $max) { - if($width > $height) { + + // very tall image (greater than 16:9) + // constrain the width - let the height float. + + if((($height * 9) / 16) > $width) { + $dest_width = $max; + $dest_height = intval(( $height * $max ) / $width); + } + + // else constrain both dimensions + + elseif($width > $height) { $dest_width = $max; $dest_height = intval(( $height * $max ) / $width); } @@ -243,8 +254,18 @@ class Photo { } else { if( $height > $max ) { - $dest_width = intval(( $width * $max ) / $height); - $dest_height = $max; + + // very tall image (greater than 16:9) + // constrain the width - let the height float. + + if((($height * 9) / 16) > $width) { + $dest_width = $max; + $dest_height = intval(( $height * $max ) / $width); + } + else { + $dest_width = intval(( $width * $max ) / $height); + $dest_height = $max; + } } else { $dest_width = $width;