php图像调整大小创建质量较低的图像

时间:2013-03-05 16:04:52

标签: php gd

我正在使用简单的图像调整大小的方法

list($width, $height) = getimagesize($filename);
$new_width = $width * $percent;
$new_height = $height * $percent;


$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);


imagejpeg($image_p, null, 100);

Eventhoug我已经将质量提升到最大,当涉及到较小的图像尺寸时,生成的图像质量非常差(原始的500px到新的100px)。

还有其他方法可以提高图像质量吗?

2 个答案:

答案 0 :(得分:3)

是的,有一种方法可以提高质量:如果可能的话,使用ImageMagick代替GD库。 GD库的质量很差。

答案 1 :(得分:0)

试试这个

<?php

header('Content-type: image/jpeg');

$image = new Imagick('image.jpg');

// If 0 is provided as a width or height parameter,
// aspect ratio is maintained
$image->thumbnailImage(100, 0);

echo $image;

?>

来源http://php.net/manual/en/imagick.examples-1.php

相关问题