Specifications
The function returns a color identifier that we can use to access the color later on.
Second, to actually draw into the image, a number of different functions are available, depend-
ing on what you want to draw—lines, arcs, polygons, or text.
The drawing functions generally require the following as parameters:
• The image identifier
• The start and sometimes the end coordinates of what you want to draw
• The color you want to draw in
• For text, the font information
In this case, we used three of the drawing functions. Let’s look at each one in turn.
First, we painted a black background on which to draw using the ImageFill() function:
ImageFill($im, 0, 0, $black);
This function takes the image identifier, the start coordinates of the area to paint (x and y), and
the color to fill in as parameters.
Generating Images
C
HAPTER 19
19
G
ENERATING
IMAGES
407
One thing to note is that the coordinates of the image start from the top-left corner,
which is
x=0, y=0. The bottom-right corner of the image is x=$width, y=$height. This
is the opposite of typical graphing conventions, so beware!
NOTE
Next, we’ve drawn a line from the top-left corner (0, 0) to the bottom-right corner ($width,
$height) of the image:
ImageLine($im, 0, 0, $width, $height, $white);
This function takes the image identifier, the start point x and y for the line, the end point, and
then the color, as parameters.
Finally, we add a label to the graph:
ImageString($im, 4, 50, 150, “Sales”, $white);
The ImageString() function takes some slightly different parameters. The prototype for this
function is
int imagestring (int im, int font, int x, int y, string s, int col)
24 7842 CH19 3/6/01 3:42 PM Page 407










