cormanaz has asked for the wisdom of the Perl Monks concerning the following question:
When this is run, combined.png just has a big black square where the plot should be.#!/usr/bin/perl -w use strict; use GD; use GD::Graph::lines; my $g = new GD::Image(400,300); plot($g); my $a = new GD::Image(20,300); addon($a); my $combined = new GD::Image(420,300); $combined->copy($g,0,0,0,0,400,300); $combined->copy($a,400,0,0,0,20,300); open(OUT,">combined.png") or die "Can't open output: $!\n"; binmode OUT; print OUT $combined->png; close OUT; sub plot { my ($graphimage) = @_; my @data = ( ["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"], [ 1, 2, 5, 6, 3, 1.5, 1, 3, 4] ); my $graph = GD::Graph::lines->new(400, 300); $graph->set( x_label => 'X Label', y_label => 'Y label', title => 'Some simple graph', y_max_value => 8, y_tick_number => 8, y_label_skip => 2 ) or die $graph->error; $graphimage = $graph->plot(\@data) or die $graph->error; open(OUT,">combined-plotpart.png") or die "Can't open output: $!\n +"; binmode OUT; print OUT $graphimage->png; close OUT; return; } sub addon { my ($gdadd) = @_; my $blue = $gdadd->colorAllocate(0,0,255); $gdadd->rectangle(0,0,20,300,$blue); return; }
I'm baffled by this because when I write out the graphic in the plot subroutine (combined-plotpart.png) it has the correct graph, and I am passing it through a reference to the object just like for the addon image, which is working OK.
What am I doing wrong?
TIA....Steve
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem passing GD image object
by GrandFather (Saint) on Mar 18, 2007 at 00:19 UTC | |
by cormanaz (Deacon) on Mar 18, 2007 at 00:45 UTC | |
by GrandFather (Saint) on Mar 18, 2007 at 00:49 UTC |