From f718a18561915a6d547e96a7aef8f75283981853 Mon Sep 17 00:00:00 2001 From: rvelices Date: Sun, 19 Feb 2012 03:18:44 +0000 Subject: -mulitisize added DerivativeImage->get_scaled_size method git-svn-id: http://piwigo.org/svn/trunk@13252 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/derivative.inc.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'include/derivative.inc.php') diff --git a/include/derivative.inc.php b/include/derivative.inc.php index 2f2f4b3d1..844d93911 100644 --- a/include/derivative.inc.php +++ b/include/derivative.inc.php @@ -271,6 +271,38 @@ final class DerivativeImage } } + function get_scaled_size($maxw, $maxh) + { + $size = $this->get_size(); + if ($size) + { + $ratio_w = $size[0] / $maxw; + $ratio_h = $size[1] / $maxh; + if ($ratio_w>1 || $ratio_h>1) + { + if ($ratio_w > $ratio_h) + { + $size[0] = $maxw; + $size[1] = floor($size[1] / $ratio_w); + } + else + { + $size[0] = floor($size[0] / $ratio_h); + $size[1] = $maxh; + } + } + } + return $size; + } + + function get_scaled_size_htm($maxw=9999, $maxh=9999) + { + $size = $this->get_scaled_size($maxw, $maxh); + if ($size) + { + return 'width="'.$size[0].'" height="'.$size[1].'"'; + } + } } ?> \ No newline at end of file -- cgit v1.2.3