tags:

views:

1797

answers:

6
A: 

I'm not aware of any ready-made functions. But I suppose you could go trough every pixel of the image and change it's colour...

Jan Hancic
A: 

I haven't tried it myself but you can look at the function imagecolorset() in the GD library It does a color fill like effect, that could help with the white background.

Ólafur Waage
A: 

You could try the imagefilter function http://lv.php.net/imagefilter - but that will not give your direct access to replace one color with another, just changing the r/g/b components.

A very low level solution could be implemented using imagesetpixel http://nl2.php.net/imagesetpixel to set the new pixel values.

Simon Groenewolt
+11  A: 
Luis Melgratti
woot this answer helped me also after the fact! GD is long on functions but the doc is short on real world examples.
A: 

I had trouble making this solution work. The image cannot be a true color image. Convert it first with imagetruecolortopalette();

$imgname = "test.gif"; $im = imagecreatefromgif ($imgname);

imagetruecolortopalette($im,false, 255);

$index = imagecolorclosest ( $im, 255,255,255 ); // get White COlor imagecolorset($im,$index,92,92,92); // SET NEW COLOR

$imgname = "result.gif"; imagegif($im, $imgname ); // save image as gif imagedestroy($im);

David Crowell
A: 

@David Crowell - What if we want to change a set color on a true color image.... is there some way of doing that?

As I need to be able to do this for HTML5 video player controls

Vinny Benson