#!/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; }