diff options
author | Bharat Mediratta <bharat@menalto.com> | 2008-12-23 01:27:50 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2008-12-23 01:27:50 +0000 |
commit | f476e2169ee84922dfe48d5a5065e1eabe40713f (patch) | |
tree | cd6f5446320366cb634c72b9c95c1cdb1d6461d0 | |
parent | 0c89fdcfc88a88459c47fdf9df94f764d4ab7702 (diff) |
Change photo::img_dimensions to take the dimensions, not a photo. This lets us use it in the watermark module too
-rw-r--r-- | core/helpers/photo.php | 21 | ||||
-rw-r--r-- | core/views/admin_block_photo_stream.html.php | 3 |
2 files changed, 13 insertions, 11 deletions
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); } } diff --git a/core/views/admin_block_photo_stream.html.php b/core/views/admin_block_photo_stream.html.php index af8d8545..6f961b29 100644 --- a/core/views/admin_block_photo_stream.html.php +++ b/core/views/admin_block_photo_stream.html.php @@ -4,6 +4,7 @@ </p> <? foreach ($photos as $photo): ?> <a href="<?= url::site("photos/$photo->id") ?>"> - <img <?= photo::img_dimensions($photo, 72) ?> src="<?= $photo->thumb_url() ?>" alt="" /> + <img <?= photo::img_dimensions($photo->width, $photo->height, 72) ?> + src="<?= $photo->thumb_url() ?>" alt="" /> </a> <? endforeach ?> |