Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I want to easily create graphs in perl and output them as png's. I have Activeperl 5.6.1 and have used the PPM thing to get it. I did... ppm install gd it installed and i was feeling happy. (This was after hours of trying to find binaries). Then i ran a simple test (the one that comes in the gd.pm file) and it spat out a bad png file. I changed it to jpeg format, and it opened, but was really warped. I then changed it to 250*250 pixels and it wouldnt load properly. The version PPM downloads is 1.27 or something, that's realyl low. And it uses GD.DLL. But in ever binary distribution i have found except for zlib it had .lib and .dll.a files, no dll's!!, i need to be able to make a gd.dll with the current version of GD!. I have msvc6 which i am assuming i would use to make the dll!. HELP! please, email me at spy_oid@hotmail.com if you know anything about getting GD to work with ActivePerl 5.6.1 because the PPM version didn't work! I am sorry if this is the wrong place to ask this. Please tell me where to go if it is.

Replies are listed 'Best First'.
Re: I am killing myself over GD!!!
by thunders (Priest) on Jan 21, 2002 at 18:18 UTC

    Ok, I got the example to work on my Windows NT box, using Activestate and the same ppm-built version of GD that you have. The end of my example differs from the documented version. The important part is the last five lines where I open a filehandle and change the binmode on the open filehandle. If you don't do that it won't work. Give this code a try and see if it works for you.

    #!/usr/bin/perl -w use GD; use strict; my $im = new GD::Image(100,100); # allocate some colors my $white = $im->colorAllocate(255,255,255); my $black = $im->colorAllocate(0,0,0); my $red = $im->colorAllocate(255,0,0); my $blue = $im->colorAllocate(0,0,255); # make the background transparent and interlaced $im->transparent($white); $im->interlaced('true'); # Put a black frame around the picture $im->rectangle(0,0,99,99,$black); # Draw a blue oval $im->arc(50,50,95,75,0,360,$blue); # And fill it with red $im->fill(50,50,$red); my $png_data = $im->png; open (DISPLAY,">myfile.png") || die; binmode DISPLAY; print DISPLAY $png_data; close DISPLAY;
Re: I am killing myself over GD!!!
by thunders (Priest) on Jan 21, 2002 at 15:44 UTC

    The last version of GD to get a passing grade from CPAN was version 1.35, you could go to cpan and download that package and try to build it from source. All you should need is the nmake program, the windows version of make available here Though I can't guarantee that that will fix your problems.


    Update:

    Attempting to act on my own advice I tried to build GD from scratch. It didn't take, because gd requires several other libraries, most of which appear to be UNIX-centric. The module author admits to a lack of knowledge on how to build on Windows platforms. and points to the above mentioned precompiled packages in the documentation, which are a bit out of date.