From c95909921ea50abcb9e5f8b536ffaa52a68e6a9a Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 30 Dec 2013 21:41:13 -0800 Subject: auto-crop imported photos for things and xchans. This results in undistorted images but may result in cropping important parts of the picture. Still this will work well for 95 out of 100 cases. If the width exceeds the height by greater than 1.2 we will remove an equal margin from either side of the photo leaving the center intact. If the height exceeds the width we will chop off the bottom to make it square. This is good for most single person photographs, unless the object of interest is off-center horizontally in a wide photo - or one is trying to emphasize aspects of human anatomy which may be at the bottom of a tall photo. --- include/photo/photo_driver.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index 4896f300b..debe1bc38 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -549,8 +549,28 @@ function import_profile_photo($photo,$xchan,$thing = false) { $img = photo_factory($img_str, $type); if($img->is_valid()) { + $width = $img->getWidth(); + $height = $img->getHeight(); + + if($width && $height) { + if(($width / $height) > 1.2) { + // crop out the sides + $margin = $width - $height; + $img->cropImage(175,($margin / 2),0,$height,$height); + } + elseif(($height / $width) > 1.2) { + // crop out the bottom + $margin = $height - $width; + $img->cropImage(175,0,0,$width,$width); - $img->scaleImageSquare(175); + } + else { + $img->scaleImageSquare(175); + } + + } + else + $photo_failure = true; $p = array('xchan' => $xchan,'resource_id' => $hash, 'filename' => basename($photo), 'album' => $album, 'photo_flags' => $flags, 'scale' => 4); -- cgit v1.2.3