function get_average_color ($image
{
$y = imagesy$image);
$x = imagesx$image);
$r_total = 0;
$g_total = 0;
$b_total = 0;
$tc = imageistruecolor$image);
for ($ii=0;$ii$y$ii++) {
for ($jj=0;$jj$x$jj++) {
$rgb = imagecolorat$image, $jj, $ii);
if ($tc) {
$r_total += ($rgb >> 16) & 0xFF;
$g_total += ($rgb >> 8) & 0xFF;
$b_total += $rgb & 0xFF;
$count++;
} else {
$rgb = imagecolorsforindex$image, $rgb);
if ($rgb'alpha']==0) {
$r_total += $rgb'red'];
$g_total += $rgb'green'];
$b_total += $rgb'blue'];
$count++;
}
}
}
}
$r = dechexround$r_total/($count)));
$g = dechexround$g_total/($count)));
$b = dechexround$b_total/($count)));
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
}