Specifications
Cleaning Up
When you’re done with an image, you should return the resources you have been using to the
server by destroying the image identifier. You can do this with a call to ImageDestroy():
ImageDestroy($im);
Using Automatically Generated Images in Other
Pages
Because a header can only be sent once, and this is the only way to tell the browser that we are
sending image data, it is slightly tricky to embed any images we create on-the-fly in a regular
page. Three ways you can do it are as follows:
1. You can have an entire page consist of the image output, as we did in the previous
example.
2. You can write the image out to a file as previously mentioned, and then refer to it with a
normal <IMG> tag.
3. You can put the image production script in an image tag.
We have covered methods 1 and 2 already. Let’s briefly look at method 3.
To use this method, you include the image inline in HTML by having an image tag along the
lines of the following:
<img src=”simplegraph.php” height=200 width=200 alt=”Sales going down”>
Instead of putting in a PNG, JPEG, or GIF directly, put in the PHP script that generates the image
in the SRC tag. This will be retrieved and the output added inline, as shown in Figure 19.3.
Using Text and Fonts to Create Images
We’ll look at a more complicated example. It is useful to be able to create buttons or other
images for your Web site automatically. You can build simple buttons based on a rectangle of
background color using the techniques we’ve already discussed.
In this example, however, we’ll generate buttons using a blank button template that allows us
to have features like beveled edges and so on, which are a good deal easier to generate using
Photoshop, the GIMP, or some other graphics tool. With the image library in PHP, we can
begin with a base image and draw on top of that.
Advanced PHP Techniques
P
ART IV
410
24 7842 CH19 3/6/01 3:42 PM Page 410










