0
我正在使用下面的php函数来裁剪图像。当图像被裁剪时,图像背景看起来像模糊。像低音图像一样。它应该是纯白色的背景色:为什么使用PHP裁剪图像时图像背景颜色显示模糊?
模糊图像:
PHP代码为波纹管:
function crop_image ($target, $newcopy, $w, $h, $ext) {
$ext = strtolower($ext);
if ($ext == "gif"){
$image = imagecreatefromgif($target);
} else if($ext =="png"){
$image = imagecreatefrompng($target);
} else {
$image = imagecreatefromjpeg($target);
}
$filename = $newcopy;
$thumb_width = $w;
$thumb_height = $h;
$width = imagesx($image);
$height = imagesy($image);
$original_aspect = $width/$height;
$thumb_aspect = $thumb_width/$thumb_height;
if ($original_aspect >= $thumb_aspect)
{
$new_height = $thumb_height;
$new_width = $width/($height/$thumb_height);
}
else
{
$new_width = $thumb_width;
$new_height = $height/($width/$thumb_width);
}
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
$color = imagecolorallocate($thumb, 255, 255, 255);
imagefill($thumb, 0, 0, $color);
imagecopyresampled($thumb,
$image,
0 - ($new_width - $thumb_width)/2, // Center the image horizontally
0 - ($new_height - $thumb_height)/2, // Center the image vertically
0, 0,
$new_width, $new_height,
$width, $height);
imagejpeg($thumb, $filename, 80);
}
OH让我做到这一点。 –
你是对的:) –