summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorIan Denhardt <ian@zenhack.net>2010-08-04 11:52:54 -0400
committerIan Denhardt <ian@zenhack.net>2010-08-04 11:52:54 -0400
commit78d9edd431d7f0f2bfbd47112edbf72e37c13bc6 (patch)
tree15291d04db6d5c3d387e458a12f633d02437a29e /plugins
parent727758d27529c6423fd885698094507a8d190ac4 (diff)
Photos are cropped now.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/GNUsocialPhotos/actions/photos.php26
1 files changed, 13 insertions, 13 deletions
diff --git a/plugins/GNUsocialPhotos/actions/photos.php b/plugins/GNUsocialPhotos/actions/photos.php
index c8b33230e..4a927782a 100644
--- a/plugins/GNUsocialPhotos/actions/photos.php
+++ b/plugins/GNUsocialPhotos/actions/photos.php
@@ -126,26 +126,26 @@ class PhotosAction extends Action
return false;
}
- $image_dest = imagecreatetruecolor($width_dest, $height_dest);
$size_src = getimagesize(INSTALLDIR . '/file/' . $filename);
$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);
+ $ratio_src = (float) $width_src / (float) $height_src;
+ $ratio_dest = (float) $width_dest / (float) $height_dest;
-
- if ($width_hmax > $width_dest) {
- $width_hmax = $width_dest;
+ if ($ratio_src > $ratio_dest) {
+ $height_crop = $height_src;
+ $width_crop = (int)($height_crop * $ratio_dest);
+ $x_crop = ($width_src - $width_crop) / 2;
} else {
- $height_wmax = $height_dest;
- }
+ $width_crop = $width_src;
+ $height_crop = (int)($width_crop / $ratio_dest);
+ $x_crop = 0;
+ }
- 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);
+ $image_dest = imagecreatetruecolor($width_dest, $height_dest);
+
+ imagecopyresampled($image_dest, $image_src, 0, 0, $x_crop, 0, $width_dest, $height_dest, $width_crop, $height_crop);
switch ($image_type) {
case IMAGETYPE_JPEG:
imagejpeg($image_dest, INSTALLDIR . '/file/' . 'thumb.' . $filename, 100);