http://lmgtfy.com/?q=gd+color+replacement I pierwszy lepszy skrypt:
function html2rgb($input)
{
$input=($input[0]=="#")?
substr($input, 1
,6
):substr($input, 0
,6
); 'r'=>hexdec
( substr($input, 0, 2) ), 'g'=>hexdec
( substr($input, 2, 2) ), 'b'=>hexdec
( substr($input, 4
, 2
) ) );
}
function colorReplace($image,$oldcolor,$newcolor=false)
{
//make the colors rbg
$rgbold = html2rgb($oldcolor);
//make the old color transparant
$oldcolor = imagecolorallocate($image, $rgbold[r], $rgbold[g], $rgbold[b]);
imagecolortransparent($image, $oldcolor);
if($newcolor)
{
$rgbnew = html2rgb($newcolor);
//make a new image in the new color
$newimage = imagecreatetruecolor(imagesx($image), imagesy($image));
//color the new image
$newcolor = imagecolorallocate($image,$rgbnew[r], $rgbnew[g], $rgbnew[b]);
imagefill($newimage, 0, 0, $newcolor);
//paste the old image on the new colored image
imagecopymerge($newimage,$image,0,0,0,0, imagesx($image), imagesy($image), 100);
imagecopymerge($image,$newimage,0,0,0,0, imagesx($image), imagesy($image), 100);
imagedestroy($newimage);
}
}