help with GD module

A

abcd

use GD::Graph::bars;
my @data = (
['frogs','fish','toads','rodents'],
[ 8, 3, 1, 2],
);
my $chart = GD::Graph::bars->new(700,500);
$chart->set(title => 'Ostrich diet');
$chart->set_title_font('arialbd', 24);
$chart->set_x_axis_font('arial', 16);
$chart->set_y_axis_font('arial', 16);
my $gd_object = $chart->plot(\@data);


but don't work, only open a cmd windown a nothing else!

how I can create a window with graphics?
 
Z

zentara

use GD::Graph::bars;
my @data = (
['frogs','fish','toads','rodents'],
[ 8, 3, 1, 2],
);
my $chart = GD::Graph::bars->new(700,500);
$chart->set(title => 'Ostrich diet');
$chart->set_title_font('arialbd', 24);
$chart->set_x_axis_font('arial', 16);
$chart->set_y_axis_font('arial', 16);
my $gd_object = $chart->plot(\@data);


but don't work, only open a cmd windown a nothing else!

how I can create a window with graphics?

You can use Image Magick's display utility, or even easier, put the
output in a Tk window.

Example: (attention: Tk likes it's photo's base64 encoded )

#!/usr/bin/perl -w
use GD;
use Tk;
use Tk::pNG;
use MIME::Base64;

my $main = new MainWindow;
my $photo_obj = $main->Photo(-data => get_graph() );

my $display = $main->Label(-image => $photo_obj,
)->pack(-fill=>'both', -expand=>1);

$main->Button(-text => 'exit',
-command => sub{exit}
)->pack();


MainLoop;

sub get_graph{
my $gd = GD::Image->new(400,300);
my $white = $gd->colorAllocate(255, 255, 255);
my $black = $gd->colorAllocate( 0, 0, 0);
my $red = $gd->colorAllocate(255, 0, 0);
my $green = $gd->colorAllocate( 0, 255, 0);
my $blue = $gd->colorAllocate( 0, 0, 255);
my $yellow = $gd->colorAllocate(255, 255, 0);

$gd->filledRectangle(0, 129, 199, 169, $blue);

my $poly = GD::polygon->new();
$poly->addPt(199, 149);
$poly->addPt(399, 74);
$poly->addPt(324, 149);
$poly->addPt(399, 224);
$gd->filledPolygon($poly, $yellow);
$gd->polygon ($poly, $black);
$gd->arc(199, 149, 250, 250, 0, 360, $red);

# Tk likes it's images base64encoded
return encode_base64( $gd->png() );
}

__END__


zentara
 
J

J. Gleixner

abcd said:
use GD::Graph::bars;
my @data = (
['frogs','fish','toads','rodents'],
[ 8, 3, 1, 2],
);
my $chart = GD::Graph::bars->new(700,500);
$chart->set(title => 'Ostrich diet');
$chart->set_title_font('arialbd', 24);
$chart->set_x_axis_font('arial', 16);
$chart->set_y_axis_font('arial', 16);
my $gd_object = $chart->plot(\@data);


but don't work, only open a cmd windown a nothing else!

Why would you expect it to display the image?
how I can create a window with graphics?

Use the Tk module or save it as a file and use a browser or some
other application, such as a browser, to display it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top