#!/usr/bin/perl -w # # demo script for http://taint.org/ # demo this bug like so: # # ./demo-gd-graph-bug.pl.txt 0 [works] # ./demo-gd-graph-bug.pl.txt 1 [broken] use GD; use GD::Graph; use GD::Graph::colour qw(:colours :lists :files :convert); use strict; use warnings; use Fcntl; use POSIX qw(strftime); my $gd; my $graph_data; if ($ARGV[0]) { # create all images as truecolor, with opaque background GD::Image->trueColor(1); warn "demoing trueColor bug"; } else { warn "NOT demoing trueColor bug"; } # [normally there'd be lots of parsing and gronking here] create_gd("testing"); $graph_data = GD::Graph::Data->new(); summarise(); plot_gd(); exit; # draw a few points for demo purposes sub summarise { my $ycounter = 5; foreach my $bucket (100000000, 110000000, 1130528071) { $graph_data->add_point($bucket, ((1 / $ycounter++) * 100.0)); } } sub create_gd { my $title = shift; use GD::Graph::lines; $gd = GD::Graph::lines->new(800, 400); $gd->set ( title => $title, box_axis => 1, transparent => 0, ##interlaced => 0, # show_values => 1, bgclr => "#ffffff", # doesn't seem to work?! boxclr => "#ffffff", fgclr => "#444444", labelclr => "#333333", dclrs => [ "#33cc00", # green "#ff3300", # red "#0000cc", # blue "#99cc00", # mauve "#ff9900", # orange "#cccc00", # yellowish "#333333", # dark grey "#999999" # light grey ], t_margin => 5, b_margin => 5, l_margin => 5, r_margin => 20, y_label => "\%age of mail in period", zero_axis => 1, x_labels_vertical => 0, x_tick_number => 'auto', x_number_format => \&fmt_time_t, y_min_value => 0, y_max_value => 100, ); } sub fmt_time_t { my $tt = shift; return strftime "%b %e %Y", gmtime($tt); } sub plot_gd { $gd->plot($graph_data); open(IMG, ">out.png") or die $!; binmode IMG; print IMG $gd->gd()->png(); close IMG; system ("ls -l out.png"); }