#!/usr/bin/perl use warnings; use strict; use GD; use GD::Text::Align; my $current = shift; $current ||= 500; my $goal = 10000; my $image = new GD::Image(250,500); my $black = $image->colorAllocate(0,0,0); my $white = $image->colorAllocate(255,255,255); my $red = $image->colorAllocate(255,0,0); my $top = 20; my $bottom = 400; my $dif = $bottom - $top; my $left_text_margin = 65; #background, set tranparent if you want $image->filledRectangle( 0, 0, 250, 500, $white ); #$image->rectangle($x1,$y1,$x2,$y2,$color) $image->rectangle(40,20,60,425,$black); #$image->filledEllipse($cx,$cy,$width,$height,$color) $image->filledEllipse(50,450,75,75,$red); $image->filledRectangle(40,400,60,425,$red); my $text = new GD::Text::Align( $image, font => gdLargeFont, # font => './arial.ttf', text => $goal.' Our Goal', color => $black, valign => "center", halign => "left", ); #draw goal at top $text->draw($left_text_margin,$top); #draw start at bottom $text->set_text('0 Start'); $text->draw($left_text_margin,$bottom); show_current(); open( IMAGE, ">GD-thermometer.png") || die "Couldn't open file: $!\n"; binmode( IMAGE ); print IMAGE $image->png(); close IMAGE; sub show_current{ my $curpix = 400 - ($dif/$goal)* $current; #draw text level $text->set_text("$current Current"); $text->draw($left_text_margin,$curpix); $image->filledRectangle(40,$curpix ,60,425,$red); }