imagecolorset

GD and GD2 are useful libraries for creating graphics on-the-fly. Discuss your PHP GD and GD2 scripts here.

Moderators: onion2k, General Moderators

Post Reply
bubs81
Forum Newbie
Posts: 4
Joined: Thu Jan 15, 2009 7:22 am

imagecolorset

Post by bubs81 »

Hi,

Can anyone see what is wring with this code?

Header("Content-type: image/jpg");
$imgname = "sketch.jpg";
$im = imagecreatefromjpeg($imgname);
$index = imagecolorclosest($im, 0,0,0); // get black
imagecolorset($im,$index,255,255,255); // set to white
imagepng($im);
imagedestroy($im);

I'm expecting the black color in the image to be replaced by white. All I get is the same image (looking un-edited). Any ideas?
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: imagecolorset

Post by greyhoundcode »

Not 100% about this but I suspect that it needs to be an indexed image, and perhaps the GD library is treating the image as true colour?
Post Reply