1 |
mikal |
1.1 |
#!/usr/bin/perl |
2 |
|
|
|
3 |
|
|
# Draw a progress bar in a given state |
4 |
|
|
# Copyright (C) Michael Still 2005 |
5 |
|
|
# Written 27 March 2005 |
6 |
|
|
|
7 |
|
|
use strict; |
8 |
|
|
use GD; |
9 |
|
|
|
10 |
|
|
my($image, $black, $white, $red, $green, $blue, $count); |
11 |
|
|
|
12 |
|
|
# Configuration for the graph |
13 |
|
|
my($graphx, $graphy) = (250, 40); |
14 |
|
|
my($leftmargin, $rightmargin, $topmargin, $bottommargin) = (10, $graphx - 10, 10, $graphy - 10); |
15 |
|
|
|
16 |
|
|
# A new image, with some colours and a given background... |
17 |
|
|
$image = new GD::Image($graphx, $graphy); |
18 |
|
|
|
19 |
|
|
$red = $image->colorAllocate(255, 0, 0); |
20 |
|
|
$blue = $image->colorAllocate(0, 0, 255); |
21 |
|
|
$black = $image->colorAllocate(0, 0, 0); |
22 |
|
|
$white = $image->colorAllocate(255, 255, 255); |
23 |
|
|
|
24 |
|
|
$image->transparent($white); |
25 |
|
|
$image->interlaced('true'); |
26 |
|
|
$image->filledRectangle(0, 0, $graphx, $graphy, $white); |
27 |
|
|
|
28 |
|
|
$image->rectangle($leftmargin, $topmargin, $rightmargin, $bottommargin, $black); |
29 |
|
|
|
30 |
|
|
# And the filled bar... |
31 |
|
|
$image->filledRectangle($leftmargin + 1, $topmargin + 1, |
32 |
|
|
($ARGV[0] / $ARGV[1]) * ($rightmargin - 1), |
33 |
|
|
$bottommargin - 1, $blue); |
34 |
|
|
|
35 |
|
|
# Dump the image out to a file... |
36 |
|
|
binmode STDOUT; |
37 |
|
|
print $image->png; |