aboutsummaryrefslogtreecommitdiffstats
path: root/include/photo
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2013-12-30 21:41:13 -0800
committerfriendica <info@friendica.com>2013-12-30 21:41:13 -0800
commitc95909921ea50abcb9e5f8b536ffaa52a68e6a9a (patch)
treea31aa66c3b18bc326f6c50141061129e29b0512f /include/photo
parent5455a156b05eef1c46219297d51b51c2c688fb55 (diff)
downloadvolse-hubzilla-c95909921ea50abcb9e5f8b536ffaa52a68e6a9a.tar.gz
volse-hubzilla-c95909921ea50abcb9e5f8b536ffaa52a68e6a9a.tar.bz2
volse-hubzilla-c95909921ea50abcb9e5f8b536ffaa52a68e6a9a.zip
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.
Diffstat (limited to 'include/photo')
-rw-r--r--include/photo/photo_driver.php22
1 files changed, 21 insertions, 1 deletions
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);