Specifications

FIGURE 19.1
The script draws a black background and then adds a line and a text label for the image.
An alternative way is to read in an existing image file that you can then filter, resize, or add to.
You can do this with one of the functions ImageCreateFromPNG(), ImageCreateFromJPEG(),
or ImageCreateFromGIF(), depending on the file format you are reading in. Each of these
takes the filename as a parameter, as in, for example,
$im = ImageCreateFromPNG(“baseimage.png”);
An example is shown later in this chapter using existing images to create buttons on-the-fly.
Drawing or Printing Text onto the Image
There are really two stages to drawing or printing text on the image.
First, you must select the colors in which you want to draw. As you probably already know,
colors to be displayed on a computer monitor are made up of different amounts of red, green,
and blue light. Image formats use a color palette that consists of a specified subset of all the
possible combinations of the three colors. To use a color to draw in an image, you need to add
this color to the images palette. You must do this for every color you want to use, even black
and white.
You can select colors for your image by calling the ImageColorAllocate() function. You need
to pass your image identifier and the red, green, and blue (RGB) values of the color you want
to draw into the function.
In Listing 19.1, we are using two colors: black and white. We allocate these by calling
$white = ImageColorAllocate ($im, 255, 255, 255);
$black = ImageColorAllocate ($im, 0, 0, 0);
Advanced PHP Techniques
P
ART IV
406
24 7842 CH19 3/6/01 3:42 PM Page 406