I'm back to work on my thermometer graph generation code. Our launch date on this project is now bearing down and I need to wrap this up. Its mostly working now, but I'm working to add a few bells and whistles to the module. I had asked some questions that got me this far about two weeks ago: Seeking GD::Graph like goal-thermometer graph.

Tonight, though, I'm seeing a usage message when I try to feed a custom color into the mix. Only I don't see how my use of the ->colorAllocate() method does not confirm to the spec presented in the usage message. And for some strange reason, my system gives me no perldoc for GD::Image.

My code complains:

Usage: GD::Image::colorAllocate(image, r, g, b) at /home/hesco/sb/GD-G +raph-Thermometer/lib/GD/Graph/Thermometer.pm line 133.
and looks like this:

package GD::Graph::Thermometer; use warnings; use strict; use Carp; use GD; use GD::Text::Align; use Data::Dumper; use constant PI => 3.14; sub new { my $self = shift; my $args = shift; . . . my $image = new GD::Image($args->{width},$args->{height}); my $colors = $self->_define_colors($image, { background_color => $args->{'background_color'}, outline_color => $args->{'outline_color'}, text_color => $args->{'text_color'}, mercury_color => $args->{'mercury_color'} }); . . . return; } sub _define_colors { my $self = shift; my $image = shift; my $custom_colors = shift; print STDERR Dumper($self,$image,$custom_colors); . . . my $text_color; if (defined($custom_colors->{text_color})) { $text_color = $image->colorAllocate($custom_colors->{text_color}); } else { $text_color = $self->_black($image); } . . . return $colors; }
I'm invoking this module as follows:

#!/usr/bin/perl -w use strict; use warnings; use lib qw{/home/hesco/sb/GD-Graph-Thermometer/lib}; use GD::Graph::Thermometer; my $result = GD::Graph::Thermometer->new({ image_path => '/home/hesco/GD-Thermometer.png', goal => '80000', current => '50000', title => 'Funding the League in 2007 ($)', width => '100', height => '200', # background_color => '', text_color => [0,0,255], # outline_color => '', # mercury_color => '' }); 1;
And finally the output of my Data::Dumper invocation:

$ ./render_thermometer.pl $VAR1 = 'GD::Graph::Thermometer'; $VAR2 = bless( do{\(my $o = 137557384)}, 'GD::Image' ); $VAR3 = { 'mercury_color' => undef, 'background_color' => undef, 'outline_color' => undef, 'text_color' => [ 0, 0, 255 ] }; Usage: GD::Image::colorAllocate(image, r, g, b) at /home/hesco/sb/GD-G +raph-Thermometer/lib/GD/Graph/Thermometer.pm line 133.

I'd certainly appreciate someone with a clue on how to use this method speaking up to show me how. I've tried to pass that array of rgb values in every which way I know how. But nothing seems to work.

Thanks,
-- Hugh

UPDATE

Success!

As suggested in the replies below, I had tried dereferencing the array to feed it into the ->colorAllocate method, without success. The error messages read:

Not an ARRAY reference at /home/hesco/sb/GD-Graph-Thermometer/lib/GD/G +raph/Thermometer.pm line 133.
Even when I tried my best to feed it an array reference. But here is the code which worked, inserting into the module itself, at line 133:

my $text_color; if (defined($custom_colors->{text_color})) { $text_color = $image->colorAllocate( $custom_colors->{text_color}[0], $custom_colors->{text_color}[1], $custom_colors->{text_color}[2] ); } else { $text_color = $self->_black($image); }
That code, along with the proper arguments sent to my constructor, turned my text labels and title blue. Next I propogate what I learned to the other code that is similarly broken.

Thank you all for your thoughts and input.

if( $lal && $lol ) { $life++; }

In reply to GD::Image::colorAllocate errors 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.