CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
GD module installed but sample graphics script produces no output

 



Newton
Novice

Jun 17, 2010, 7:34 AM

Post #1 of 8 (891 views)
GD module installed but sample graphics script produces no output Can't Post

Hi,
After installing the GD module from source (to get around the "Can't locate loadable module for GD in @INC" etc). I tried the following sample script (from the book Graphics Programming With Perl by MVerbruggen) and got absolutely no output whatsoever (and also no errors or warnings):

Code
#!/usr/bin/perl -w 
use strict;
use GD;
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);
$gd->arc(199, 149, 100, 200, 0, 360, $red);
$gd->fillToBorder(99, 149, $red, $green);
$gd->rectangle(0, 0, 399, 299, $red);
$gd->line(199, 0, 199, 299, $red);
$gd->line(0, 149, 399, 149, $red);

Code
 
I'm working on a Ubuntu 10.04 LTS lucid machine.
I'm new to graphics programming and would really like to get up to speed on it.
Any help/advice would be greatly appreciated.
Thanks in advance.


Bianca
User

Jun 17, 2010, 8:19 AM

Post #2 of 8 (889 views)
Re: [Newton] GD module installed but sample graphics script produces no output [In reply to] Can't Post


In Reply To
got absolutely no output whatsoever (and also no errors or warnings)


Why do you not ask for output?
For example as PNG format: print $gd->png;


shawnhcorey
Enthusiast


Jun 17, 2010, 8:52 AM

Post #3 of 8 (887 views)
Re: [Newton] GD module installed but sample graphics script produces no output [In reply to] Can't Post

If you're using Ubuntu, then it's easier to install GD via the Synaptic Package Manager. The package name is libgd-gd2-perl

You may also want to consider additional packages like libgd-text-perl, libgd-graph-perl and libdg-graph3d-perl

To get a complete list, do a Quick Search for: libgd perl

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


Newton
Novice

Jun 17, 2010, 10:11 AM

Post #4 of 8 (883 views)
Re: [Bianca] GD module installed but sample graphics script produces no output [In reply to] Can't Post

Hi and thank-you for replying.
I'm totally new to GD and Perl graphics programming - all my Perl experience is in bioinformatics. Pretty foolish of me not to ask for output as you suggested. Unfortunately, when I added the line you suggested I didn't get the expected image but instead got a screenful of binary gibberish. What am I messing up? Incorrect installation of the GD library itself?
Once again I greatly appreciate your and the other poster's assistance.


Bianca
User

Jun 17, 2010, 11:41 AM

Post #5 of 8 (879 views)
Re: [Newton] GD module installed but sample graphics script produces no output [In reply to] Can't Post

Question is what do you want to do with the picture. If you run script in CGI with webserver make
binmode STDOUT; and print.
If you want to write in file make open(....) and write it in the file.
But always use binmode() bevor giving out!


Newton
Novice

Jun 18, 2010, 8:22 AM

Post #6 of 8 (866 views)
Re: [Bianca] GD module installed but sample graphics script produces no output [In reply to] Can't Post

I have added the following lines to the code in the original post:

Code
binmode STDOUT; 
print $gd->png;


but am still getting the same result i.e. no image.

I am getting the same result when I run the first example (second code window) from http://search.cpan.org/~lds/GD-2.45/GD.pm as well.

Any help is greatly appreciated.


Bianca
User

Jun 18, 2010, 9:16 AM

Post #7 of 8 (863 views)
Re: [Newton] GD module installed but sample graphics script produces no output [In reply to] Can't Post

yes, it's correct.
Second time this question: What do you want to do with the generated Image?
If you print in console you get peeep peeep, it's normal, it's binary code!!!

You are generating a Image, that's binary. You can not show this in console. You have to print it to browser via cgi (f.e. you request your script between <img src="myscript.pl">) or you have to write into file and open it with a image viewer like irfanview or else.

Understand my?
Sorry for my bad english.


Newton
Novice

Jun 18, 2010, 3:51 PM

Post #8 of 8 (854 views)
Re: [Bianca] GD module installed but sample graphics script produces no output [In reply to] Can't Post

Bianca,
There is absolutely nothing wrong with your English! The problem is on my end. I opened a file for writing, binmoded it, wrote the image to it and it all worked perfectly when I opened it with eog. As I said before all my experience is in bioinformatics with none in Perl and graphics programming so I committed a series of newbie mistakes.

Thank-you very much for your help and especially for your patience!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives