From 1c2d4de4696f8719bfbd8e98a2039229babfa15a Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 14 Apr 2011 23:57:30 -0400 Subject: [PATCH] scale down the thumbnail image if necessary --- plugins/Bookmark/bookmarkform.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/plugins/Bookmark/bookmarkform.php b/plugins/Bookmark/bookmarkform.php index ffeba312ea..f6341a0a72 100644 --- a/plugins/Bookmark/bookmarkform.php +++ b/plugins/Bookmark/bookmarkform.php @@ -122,11 +122,14 @@ class BookmarkForm extends Form $this->_url); $this->unli(); + list($width, $height) = $this->scaleImage($this->_thumbnail->width, + $this->_thumbnail->height); + if (!empty($this->_thumbnail)) { $this->out->element('img', array('src' => $this->_thumbnail->url, - 'width' => $this->_thumbnail->width, - 'height' => $this->_thumbnail->height)); + 'width' => $width, + 'height' => $height)); } $this->li(); @@ -173,4 +176,20 @@ class BookmarkForm extends Form // TRANS: Button text for action to save a new bookmark. $this->out->submit('submit', _m('BUTTON', 'Save')); } + + function scaleImage($width, $height) + { + $maxwidth = common_config('attachments', 'thumb_width'); + $maxheight = common_config('attachments', 'thumb_height'); + + if ($width > $height && $width > $maxwidth) { + $height = (int) ((((float)$maxwidth)/(float)($width))*(float)$height); + $width = $maxwidth; + } else if ($height > $maxheight) { + $width = (int) ((((float)$maxheight)/(float)($height))*(float)$width); + $height = $maxheight; + } + + return array($width, $height); + } } -- 2.39.5