Specifications
$text_color = $black;
$percent_color = $black;
$bg_color = $white;
$line_color = $black;
$bar_color = $blue;
$number_color = $pink;
// Create “canvas” to draw on
ImageFilledRectangle($im,0,0,$width,$height,$bg_color);
// Draw outline around canvas
ImageRectangle($im,0,0,$width-1,$height-1,$line_color);
// Add title
$title = “Poll Results”;
$title_dimensions = ImageTTFBBox($title_size, 0, $font, $title);
$title_length = $title_dimensions[2] - $title_dimensions[0];
$title_height = abs($title_dimensions[7] - $title_dimensions[1]);
$title_above_line = abs($title_dimensions[7]);
$title_x = ($width-$title_length)/2; // center it in x
$title_y = ($y - $title_height)/2 + $title_above_line; // center in y gap
ImageTTFText($im, $title_size, 0, $title_x, $title_y,
$text_color, $font, $title);
// Draw a base line from a little above first bar location
// to a little below last
ImageLine($im, $x, $y-5, $x, $height-15, $line_color);
In Part 3, we set up the basic image, allocate the colors, and then begin to draw the graph.
We fill in the background for the graph this time using
ImageFilledRectangle($im,0,0,$width,$height,$bg_color);
The ImageFilledRectangle() function, as you might imagine, draws a filled-in rectangle. The
first parameter is, as usual, the image identifier. Then we must pass it the X and Y coordinates
of the start point and the end point of the rectangle. These correspond to the upper-left corner
and the lower-right corner, respectively. In this case, we are filling the entire canvas with the
background color, which is the last parameter, and it’s white.
We then call
ImageRectangle($im,0,0,$width-1,$height-1,$line_color);
Generating Images
C
HAPTER 19
19
G
ENERATING
IMAGES
425
LISTING 19.5.3 Continued
24 7842 CH19 3/6/01 3:42 PM Page 425










