调整图像与GD没有颜色损失


Resizing images with GD without color loss

我正在尝试用GD调整图像的大小,并且在调整大小的图像上看到颜色损失。下面是我的代码:

$src = imagecreatefromstring(file_get_contents($source)); 
ImageCopyResized($dst, $src, 0, 0, 0, 0, $t_width, $t_height, ImageSX($src), ImageSY($src)); 
Imagejpeg($dst, $dest, 90);

在声明$dst时是否使用imagecreatetruecolor ?

正确的做法是:

$dst = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($dst, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);