Adrian B
Adrian B

Reputation: 1631

Resizing images with GD without color loss

I'm trying to resize an image with GD and am seeing a color loss on the resized image. Here is my code:

$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);

Upvotes: 0

Views: 1618

Answers (2)

Adrian B
Adrian B

Reputation: 1631

The right way to do this is:

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

Upvotes: 0

simshaun
simshaun

Reputation: 21476

Are you using imagecreatetruecolor when declaring $dst?

Upvotes: 1

Related Questions