Zistenie indexu určitej farby.

<? 
$im = @ImageCreateFromGif('obrazok.gif'); /* Skus otvorit */ 
if ($im == "") { /* Ak nemoze otvorit */ 
   $im = ImageCreate(100, 30); 
   $bgc = ImageColorAllocate($im,255,255,255); 
   $tc = ImageColorAllocate($im,0,0,0); 
   ImageFilledRectangle($im, 0, 0, 150, 30, $bgc); 
   ImageString($im, 1, 10, 10, "Error loading", $tc); /* Vypise chybu */ 
}else{ 
   $nc = ImageColorExact($im, 100, 200, 0); /* Zisti index farby */ 
   //ImageColorExact(image, red, green, blue); 
 
   if ($nc==-1) { //Ak farba nieje definovana 
       $nc=ImageColorAllocate($im, 100, 200, 0); 
   } 
 
   ImageString($im, 1, 10, 13, "Ahoj", $nc); 
} 
 
Header("Content-type: image/gif"); 
ImageGif($im); 
?>