【发布时间】:2017-10-27 16:00:54
【问题描述】:
这可能是重复的,但我看过的每个解决方案似乎都不适合我,所以不确定我在做什么不同。
我对图像处理还不太了解,但是当使用 imagecopyresampled 将图像放置在另一个图像上时,裁剪图像似乎会在图像的右侧/底部添加大量黑色空间。它们都是 JPEG。
这是我的裁剪功能:
function thumbImage($thumb_img,$img_size,$shape){
$width = 250;
$height = 250;
list($w, $h) = $img_size;
if($w > $h) {
$new_height = $height;
$new_width = floor($w * ($new_height / $h));
$crop_x = ceil(($w - $h) / 2);
$crop_y = 0;
} else {
$new_width = $width;
$new_height = floor( $h * ( $new_width / $w ));
$crop_x = 0;
$crop_y = ceil(($h - $w) / 2);
}
$tmp_img = imagecreatetruecolor($width,$height);
imagecopyresampled($tmp_img, $thumb_img, 0, 0, $crop_x, $crop_y, $new_width, $new_height, $w, $h);
return $tmp_img;
}
任何解释其工作原理的解决方案将不胜感激。
【问题讨论】: