Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Adding text to a GD::Graph object...

by dree (Monsignor)
on Jun 22, 2002 at 09:56 UTC ( #176466=note: print w/replies, xml ) Need Help??

in reply to Adding text to a GD::Graph object...

GD::Text::Wrap require a GD object.
So you have to put the 3d graph in an image and then make a GD object with it to pass to GD::Text::Wrap.

This works for me:
use GD; use GD::Graph::bars3d; use GD::Text::Wrap; use strict; my @data = ( ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], [ 1203, 3500, 3973, 2859, 3012, 3423, 1230] ); my $graph = GD::Graph::bars3d->new( 400, 300 ); $graph->set( x_label => 'Day of the week', y_label => 'Number of hits', title => 'Daily Summary of Web Site', ); my $gd = $graph->plot( \@data ); my $img_tmp="img_tmp.png"; open FILE, ">$img_tmp"; binmode FILE; print FILE $gd->png; close FILE; my $gd_image = GD::Image->newFromPng($img_tmp) ; my $text = <<EOSTR; Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. EOSTR my $wrapbox = GD::Text::Wrap->new( $gd_image, line_space => 4, color => 'black', text => $text, ); $wrapbox->set(align => 'left', width => 120); $wrapbox->draw(110,140); open FILE, ">img.png"; binmode FILE; print FILE $gd_image->png; close FILE;

In my Win32 box, it works properly with GD 1.27.2.
If you have a more recent version of GD, instead making a temporary image, you could use:
my $gd_image = GD::Image->newFromPngData($gd->png);

Replies are listed 'Best First'.
Re: Re: Adding text to a GD::Graph object...
by Clownburner (Monk) on Jun 25, 2002 at 19:37 UTC

    THere's just one problem: It doesn't work for me. :-(

    Any suggestions? Maybe I've got a bad library somewhere?

    > ./ Not a GD::Image object at ./ line 26 > perl -mGD -e 'print "$GD::VERSION\n"' 1.33 > perl -v This is perl, version 5.005_03 built for i386-linux

    "Non sequitur. Your facts are un-coordinated." - Nomad

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://176466]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2017-10-21 11:05 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (269 votes). Check out past polls.