function allocate_color ($image, $color, $transparency
{
if (preg_match'/[0-9ABCDEF]{6}/i', $color)==0) {
throw new Exception"Invalid color code.");
}
if ($transparency<0 || $transparency>127) {
throw new Exception"Invalid transparency.");
}
$r = hexdecsubstr$color, 0, 2));
$g = hexdecsubstr$color, 2, 2));
$b = hexdecsubstr$color, 4, 2));
if ($transparency>127) $transparency = 127;
if ($transparency<=0)
return imagecolorallocate$image, $r, $g, $b);
else
return imagecolorallocatealpha$image, $r, $g, $b, $transparency);
}
eXorithm – Execute Algorithm: View / Run Algorithm allocate_color
