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.

This commit is contained in:
friendica 2013-12-30 21:41:13 -08:00
parent 5455a156b0
commit c95909921e

View file

@ -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);