From f476e2169ee84922dfe48d5a5065e1eabe40713f Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 23 Dec 2008 01:27:50 +0000 Subject: Change photo::img_dimensions to take the dimensions, not a photo. This lets us use it in the watermark module too --- core/helpers/photo.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'core/helpers') diff --git a/core/helpers/photo.php b/core/helpers/photo.php index bb470e58..10f3d1a0 100644 --- a/core/helpers/photo.php +++ b/core/helpers/photo.php @@ -107,18 +107,19 @@ class photo_Core { /** * Return scaled width and height. * - * @param Item_Model the photo - * @param integer the scaling factor - * @param string the output format using %d placeholders for width and height + * @param integer $width + * @param integer $height + * @param integer $max the target size for the largest dimension + * @param string $format the output format using %d placeholders for width and height */ - static function img_dimensions($photo, $max, $format="width=\"%d\" height=\"%d\"") { - if ($photo->width > $photo->height) { - $width = $max; - $height = (int)$max * ($photo->height / $photo->width); + static function img_dimensions($width, $height, $max, $format="width=\"%d\" height=\"%d\"") { + if ($width > $height) { + $new_width = $max; + $new_height = (int)$max * ($height / $width); } else { - $height = $max; - $width = (int)$max * ($photo->width / $photo->height); + $new_height = $max; + $new_width = (int)$max * ($width / $height); } - return sprintf($format, $width, $height); + return sprintf($format, $new_width, $new_height); } } -- cgit v1.2.3