我必须用PHP调整图片大小。 但是...质量非常非常糟糕! (看图)调整图片质量而不损失
这里我的代码:
function _copyAndResizeImage($id, $wanted_width, $isAdvert=true) {
// The file
if ($isAdvert) {
$filename = "../upload/images/advert/".$id."/1.jpg";
} else {
$filename = "../upload/images/user/".$id.".jpg";
}
list($width, $height) = getimagesize($filename);
if ($width == 0) {
$percent=1;
} else {
$percent = $wanted_width/$width;
}
// Content type
header('Content-Type: image/jpeg');
// Get new dimensions
$new_width = $width * $percent;
$new_height = $height * $percent;
// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Output
if ($isAdvert) {
imagejpeg($image_p, '../upload/images/advert/'.$id.'/1-'.$wanted_width.'.jpg');
} else {
imagejpeg($image_p, '../upload/images/user/'.$id.'-'.$wanted_width.'.jpg');
}
}
你有一个想法? 由于
那么,这就是扩大一个小图像将要做的事,没有办法解决这个问题。你的原始图像有多大? –
我没有得到源代码,但是,源代码的大小通常较大 –
请尝试像[phpThumb](http://phpthumb.sourceforge.net/)这样的库,或者在函数imagejpeg中添加图像质量参数' – bystwn22