Color-retrieval functions could be combined into a custom function
<?php
function getcolor($img, $red, $green, $blue) {
$color = imagecolorexact($img, $red, $green, $blue);
if($color == -1) {
$color = imagecolorallocate($img, $red, $green, $blue);
if($color == -1) {
$color = imagecolorclosest($img, $red, $green, $blue);
}
}
return $color;
}
?>
Related examples in the same category