Can I swap colors in image using GD library in PHP?

Skuta picture Skuta · Jan 18, 2009 · Viewed 17.6k times · Source

I got the image like this (it's a graph):

Gold Trade Graph
(source: kitconet.com)

I want to change the colours, so the white is black, the graph line is light blue, etc.. is it possible to achieve with GD and PHP?

Answer

Luis Melgratti picture Luis Melgratti · Jan 19, 2009

This will replace the white color with Gray

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

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

enter image description here