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: Beginner:
GD::Simple

 



jeffreysmith300
New User

Dec 11, 2015, 11:02 AM

Post #1 of 2 (976 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 http://rosettacode.org/wiki/Fractal_tree 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);
$img->fgcolor('black');
$img->penSize(1,1);

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

print $img->png;


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

return if $len < 1;

$img->moveTo($x,$y);
$img->angle($angle);
$img->line($len);

($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?


Zhris
Enthusiast

Dec 11, 2015, 11:58 PM

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

Hi,

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.

Chris

 
 


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

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