function blend_colors ($color1, $color2, $weight
{
if ($weight<0 || $weight>1)
throw new Exception"Weight must be between 0 and 1");
$r1 = hexdecsubstr$color1, 0, 2));
$g1 = hexdecsubstr$color1, 2, 2));
$b1 = hexdecsubstr$color1, 4, 2));
$r2 = hexdecsubstr$color2, 0, 2));
$g2 = hexdecsubstr$color2, 2, 2));
$b2 = hexdecsubstr$color2, 4, 2));
$r = dechexround$r1$weight + $r2*(1-$weight)));
$g = dechexround$g1$weight + $g2*(1-$weight)));
$b = dechexround$b1$weight + $b2*(1-$weight)));
if (strlen$r)==1) $r = '0'$r
if (strlen$g)==1) $g = '0'$g
if (strlen$b)==1) $b = '0'$b
return $r$g$b
}