Specifications
Writing the Text onto the Button
After that, it’s all smooth sailing. We set up the text color, which will be white:
$white = ImageColorAllocate ($im, 255, 255, 255);
We can then use the ImageTTFText() function to actually draw the text onto the button:
ImageTTFText ($im, $font_size, 0, $text_x, $text_y, $white, “arial.ttf”,
$button_text);
This function takes quite a lot of parameters. In order, they are the image identifier, the font
size in points, the angle we want to draw the text at, the starting X and Y coordinates of the
text, the text color, the font file, and, finally, the actual text to go on the button.
Generating Images
C
HAPTER 19
19
G
ENERATING
IMAGES
419
The font file needs to be available on the server, and is not required on the client’s
machine because she will see it as an image. By default, the function will look for the
file in the same directory that the script is running in. Alternatively, you can specify a
path to the font.
NOTE
Finishing Up
Finally, we can output the button to the browser:
Header (“Content-type: image/png”);
ImagePng ($im);
Then it’s time to clean up resources and end the script:
ImageDestroy ($im);
That’s it! If all went well, we should now have a button in the browser window that looks simi-
lar to the one you saw in Figure 19.5.
Drawing Figures and Graphing Data
In that last application, we looked at existing images and text. We haven’t yet looked at an
example with drawing, so we’ll do that now.
In this example, we’ll run a poll on our Web site to test whom users will vote for in a fictitious
election. We’ll store the results of the poll in a MySQL database, and draw a bar chart of the
results using the image functions.
24 7842 CH19 3/6/01 3:42 PM Page 419










