Specifications
ImageFilledRectangle($im, $x, $y-2, $bar_length, $y+$bar_height, $bar_color);
// draw title for this value
ImageTTFText($im, $main_size, 0, $text_indent, $y+($bar_height/2),
$text_color, $font, “$row->candidate”);
// draw outline showing 100%
ImageRectangle($im, $bar_length+1, $y-2,
($x+(100*$bar_unit)), $y+$bar_height, $line_color);
// display numbers
ImageTTFText($im, $small_size, 0, $x+(100*$bar_unit)-50, $y+($bar_height/2),
$number_color, $font, $row->num_votes.”/”.$total_votes);
// move down to next bar
$y=$y+($bar_height+$bar_spacing);
}
/*******************************************
Display image
*******************************************/
Header(“Content-type: image/png”);
ImagePng($im);
/*******************************************
Clean up
*******************************************/
ImageDestroy ($im);
?>
Part 4 goes through the candidates from the database one by one, works out the percentage of
votes, and draws the bars and labels for each candidate.
Again we add labels using ImageTTFText(). We draw the bars as filled rectangles using
ImageFilledRectangle():
ImageFilledRectangle($im, $x, $y-2, $bar_length, $y+$bar_height, $bar_color);
We add outlines for the 100% mark using ImageRectangle():
ImageRectangle($im, $bar_length+1, $y-2,
($x+(100*$bar_unit)), $y+$bar_height, $line_color);
After we have drawn all the bars, we again output the image using ImagePNG(), and clean up
after ourselves using
ImageDestroy().
Generating Images
C
HAPTER 19
19
G
ENERATING
IMAGES
427
LISTING 19.5.4 Continued
24 7842 CH19 3/6/01 3:42 PM Page 427










