*/
//attempt to open image, suppress error messages
if(!($image = @imagecreatefrompng("php.png")))
{
//error, so create an error image and exit
$image = imagecreate(200,200);
$colorWhite = imagecolorallocate($image, 255, 255, 255);
$colorBlack = imagecolorallocate($image, 0, 0, 0);
imagefill($image, 0, 0, $colorWhite);
imagestring($image, 4, 10, 10, "Couldn't load image!",
$colorBlack);
header("Content-type: image/jpeg");
imagejpeg($image);
exit();
}
//create a color to be transparent, hopefully
//not already in the image
$colorMagenta = imagecolorallocate($image, 255, 0, 255);
//draw a circle
imagearc($image,
100, 50,
100, 100,
0, 360,
$colorMagenta);
//fill outside of circle with Magenta
imagefilltoborder($image, 0, 0, $colorMagenta, $colorMagenta);
//turn magenta transparent
imagecolortransparent($image, $colorMagenta);
//send image to browser
header("Content-type: image/png");
imagepng($image);
?>
boolean imagechar(integer image, integer font, integer x,
integer y, string character, integer color)
The imagechar function draws a single character at the given pixel. The font argument
can be a loaded font or one of the five built-in fonts. The character will be oriented
horizontally—that is, left to right. The x and y coordinates refer to the top-left corner of
the letter.
Figure 12-1. imagechar.