Most people don't understand that PHP3 can also handle non-HTML types of data, such as images, which we can use to create bars, columns, and pie charts to react to database data, and we can use PHP3 to create nice graphics buttons. Most of the graphics button is done with the image editing tool, for the image of inexperienced programmers, this is a chore, in the establishment of a site, the button's style is mostly unified, the difference is the word on the button, in order to relieve the distress, We can use the TTF font and PHP3 graphics function library to create a button function, need to press the button when the call can be, the following is the program BUTTON.PHP3:
This function passes two parameters, $s is the font size, $text is the word, if there is a space with the + number instead
?
Header ("Content-type:image/gif");
Default font size, 11 if not set
if (!isset ($s)) $s = 11;
/* Compute the area of TTF text text
function Imagettfbbox (font size, rotation angle, font path, word)
Returns an array with eight array elements
Size[0]= left Lower X coordinate
Size[1]= left Lower y-coordinate
size[2]= right Lower X coordinate
size[3]= right Lower y-coordinate
size[4]= right Upper X coordinate
size[5]= Right y-coordinate
Size[4]= left Upper X coordinate
Size[5]= left Upper y-coordinate
*/
$size = Imagettfbbox ($s, 0, "/fonts/times." TTF ", $text);
The length of the string and the absolute value of the height, if double,abs or double, and the other abs become int type
$DX = ABS ($size [2]-$size [0]);
$dy = ABS ($size [5]-$size [3]);
For the top and bottom left 4 pixels around the gap, plus a pixel shadow, a total of 4*2+1=9
$xpad = 9;
$ypad = 9;
Create an image area
$im = imagecreate ($dx + $xpad, $dy + $ypad);
Set color imagecolorallocate (image handle, red,green,blue) three primary Colors
$blue = Imagecolorallocate ($im, 0X2C,0X6D,0XAF);
$black = Imagecolorallocate ($im, 0,0,0);
$white = Imagecolorallocate ($im, 255,255,255);
Draw rectangular imagerectangle (image handle, upper left X, upper left y, lower right x, lower right y, color)
Draw a Shadow
Imagerectangle ($im, 1,1, $dx + $xpad, $dy + $ypad, $black); Imagerectangle ($im, 0,0, $DX + $xpad-1, $dy + $ypad-1, $white); Imagerectangle ($im, 1,1, $DX + $xpad-1, $dy + $ypad-1, $blue);
Write body to Image
Imagettftext (image handle, font size, rotation angle, Word left upper X, Word left upper y, color, font path, word)
Draw a Shadow
Imagettftext ($im, $s, 0, (int) ($xpad/2) +1, $dy + (int) ($ypad/2), $black, "/fonts/times." TTF ", $text);
Imagettftext ($im, $s, 0, (int) ($xpad/2), $dy + (int) ($ypad/2)-1, $white, "/fonts/times." TTF ", $text);
Convert to GIF
Imagegif ($im);
Imagedestroy ($im);
?>
Note: Do not include any HTML code in this file at the same time. And?> can not have a blank line, otherwise the program will not function normally, this function will eventually create a pair of images.