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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:


New User

Dec 11, 2015, 11:02 AM

Post #1 of 2 (1346 views)
GD::Simple Can't Post

i'm new to this module and have no idea what i'm doing.

I copied some code from to create a fractal tree image.

here's the code i'm using

use GD::Simple;

my ($width, $height) = (1000,1000); # image dimension
my $scale = 6/10; # branch scale relative to trunk
my $length = 400; # trunk size

my $img = GD::Simple->new($width,$height);

tree($width/2, $height, $length, 270);

print $img->png;

sub tree
my ($x, $y, $len, $angle) = @_;

return if $len < 1;


($x, $y) = $img->curPos();

tree($x, $y, $len*$scale, $angle+35);
tree($x, $y, $len*$scale, $angle-35);

when i run this code all i get is what looks like the binary data for an image. i tried outputting the results to a file (test.png) but i get an error saying its a corrupt file when i open the file with an image editor.

anyone have an idea?


Dec 11, 2015, 11:58 PM

Post #2 of 2 (1326 views)
Re: [jeffreysmith300] GD::Simple [In reply to] Can't Post


If you print to stdout, as your code currently does, you will indeed see the raw binary data. I suspect when you tried outputting to a file you forgot to binmode the filehandle I.e. binmode $filehandle;, could you show us the relevant code.



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

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