I hope I get a merit badge for this. :-) This will take the current amount on the commandline and generate the thermometer. It could use some enhancements, but it should get you started.
#!/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); }

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

In reply to Re: Seeking GD::Graph like goal-thermometer graph by zentara
in thread Seeking GD::Graph like goal-thermometer graph by hesco

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.