From 727758d27529c6423fd885698094507a8d190ac4 Mon Sep 17 00:00:00 2001 From: Ian Denhardt Date: Tue, 3 Aug 2010 19:24:19 -0400 Subject: [PATCH] Fixed scaling. thumbnails are bigger now, too. --- plugins/GNUsocialPhotos/actions/photos.php | 24 ++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/plugins/GNUsocialPhotos/actions/photos.php b/plugins/GNUsocialPhotos/actions/photos.php index 1c7fb82bd2..c8b33230e3 100644 --- a/plugins/GNUsocialPhotos/actions/photos.php +++ b/plugins/GNUsocialPhotos/actions/photos.php @@ -110,8 +110,8 @@ class PhotosAction extends Action function makeThumb($filename) { - $height_dest = 96; - $width_dest = 128; + $height_dest = 192; + $width_dest = 256; if (substr($filename, -4) == '.jpg' || substr($filename, -5) == '.jpeg') { $image_src = imagecreatefromjpeg(INSTALLDIR . '/file/' . $filename); @@ -128,8 +128,24 @@ class PhotosAction extends Action $image_dest = imagecreatetruecolor($width_dest, $height_dest); $size_src = getimagesize(INSTALLDIR . '/file/' . $filename); - - imagecopyresampled($image_dest, $image_src, 0, 0, 0, 0, $width_dest, $height_dest, $size_src[0], $size_src[1]); + $width_src = $size_src[0]; + $height_src = $size_src[1]; + + // We want to make the image as big as possible without distortion. + $width_hmax = $width_src / ((float)$height_src / (float)$height_dest); + $height_wmax = $height_src / ((float)$width_src / (float)$width_dest); + + + if ($width_hmax > $width_dest) { + $width_hmax = $width_dest; + } else { + $height_wmax = $height_dest; + } + + common_log(LOG_INFO, 'height_wmax = ' . $height_wmax); + common_log(LOG_INFO, 'width_hmax = ' . $width_hmax); + + imagecopyresampled($image_dest, $image_src, 0, 0, 0, 0, (int)($width_hmax), (int)($height_wmax), $width_src, $height_src); switch ($image_type) { case IMAGETYPE_JPEG: imagejpeg($image_dest, INSTALLDIR . '/file/' . 'thumb.' . $filename, 100); -- 2.39.2