forked from GNUsocial/gnu-social
Photos are cropped now.
This commit is contained in:
parent
727758d275
commit
78d9edd431
@ -126,26 +126,26 @@ class PhotosAction extends Action
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$image_dest = imagecreatetruecolor($width_dest, $height_dest);
|
|
||||||
$size_src = getimagesize(INSTALLDIR . '/file/' . $filename);
|
$size_src = getimagesize(INSTALLDIR . '/file/' . $filename);
|
||||||
$width_src = $size_src[0];
|
$width_src = $size_src[0];
|
||||||
$height_src = $size_src[1];
|
$height_src = $size_src[1];
|
||||||
|
|
||||||
// We want to make the image as big as possible without distortion.
|
$ratio_src = (float) $width_src / (float) $height_src;
|
||||||
$width_hmax = $width_src / ((float)$height_src / (float)$height_dest);
|
$ratio_dest = (float) $width_dest / (float) $height_dest;
|
||||||
$height_wmax = $height_src / ((float)$width_src / (float)$width_dest);
|
|
||||||
|
|
||||||
|
if ($ratio_src > $ratio_dest) {
|
||||||
if ($width_hmax > $width_dest) {
|
$height_crop = $height_src;
|
||||||
$width_hmax = $width_dest;
|
$width_crop = (int)($height_crop * $ratio_dest);
|
||||||
|
$x_crop = ($width_src - $width_crop) / 2;
|
||||||
} else {
|
} 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);
|
$image_dest = imagecreatetruecolor($width_dest, $height_dest);
|
||||||
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);
|
imagecopyresampled($image_dest, $image_src, 0, 0, $x_crop, 0, $width_dest, $height_dest, $width_crop, $height_crop);
|
||||||
switch ($image_type) {
|
switch ($image_type) {
|
||||||
case IMAGETYPE_JPEG:
|
case IMAGETYPE_JPEG:
|
||||||
imagejpeg($image_dest, INSTALLDIR . '/file/' . 'thumb.' . $filename, 100);
|
imagejpeg($image_dest, INSTALLDIR . '/file/' . 'thumb.' . $filename, 100);
|
||||||
|
Loading…
Reference in New Issue
Block a user