Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

imagefill($image, 0, 0, $colorWhite);
imagestring($image, 4, 10, 10, "Couldn't load image!",
$colorBlack);
header("Content-type: image/jpeg");
imagejpeg($image);
exit();
}


//get the color at (100,100)
$colorIndex = imagecolorat($image, 100, 100);


//get RGB values
$colorParts = imagecolorsforindex($image, $colorIndex);


//display RGB values
printf("RGB: ".
$colorParts["red"]. ", ".
$colorParts["green"]. ", ".
$colorParts["blue"]);
?>


integer imagecolorstotal(integer image)


The imagecolorstotal function returns the number of colors in the given image.


<?
/*
* Find number of colors in an image
/


//attempt to open image, suppress error messages
if(!($image = @imagecreatefromjpeg("php_lang.jpg")))
{
//error, so print error message
print("Couldn't load image!");
}
else
{
print("Total Colors: ". imagecolorstotal
($image));
}
?>


integer imagecolortransparent (integer image, integer color)


The imagecolortransparent function sets the given color transparent. The color
argument is as returned by the imagecolorallocate functions.

Free download pdf