Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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);


Comment on Re: Adding text to a GD::Graph object...
Select or Download Code
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
    Thanks!

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

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

    > ./graphtest.pl Not a GD::Image object at ./graphtest.pl 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://176466]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (14)
As of 2015-07-30 23:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls