Code Comments
Programming Forum and web based access to our favorite programming groups.I cannot make GD (graphics or GIF display) to produce any kind of graphics from Perl. I cannot find the solution from the previous postings in this newgroup or anywhere else on the net, but others seem to have similar problems. So a rather lengthy description of the problem. Apologies in advance !!! I installed Perl 5.8.4.810 from ActiveState (a couple of times). It works very well in our Windows XP/administrator setup. Except when printing graphs on data. From the Perl Cookbook we got the idea of installing GD. The code starts out use GD::Graph::lines; ... Started out by downloading from http://www.boutell.com/gd/ the windows DLL (.zip) file. This extracts, but does not add any immediate support for GD... because Perl complains that INC cannot see GD. Also the bgd.dll and a few exe files does not seem to belong anywhere - except in the newly extracted folder. Tried to copy these files to windows and perl binary folders, but off course no action. Still, all the talk about linking seemed to be for C-programmers and/or UNIX users. There must be a way ... Also some talk about libpng and zlib. Same argument, the necessary code is hopefully available somewhere to copy or install. In the boutell doc was the message: gd can also be used from Perl, courtesy of Lincoln Stein's GD.pm library (http://stein.cshl.org/WWW/software/GD/). Downloaded that zip info. Here was a piece of (perl) code, starting out with use GD; # create a new image $im = new GD::Image(100,100); .. which would produce a graphic image of a red circle. Extracted the new zip-file, which should be ppm'ed to install. This did not work as the 'GD.PPD could not be found'. But on this group was a mention of a working ppd, namely ppm install http://theoryx5.uwinnipeg.ca/ppms/GD.ppd which had a correct PPD and completed. PPM has acknowledged a version 1.27.2 is installed. And now the above mentioned "use GD;" in the perl script is passed wihtout any problems. Unfortunately the last lines of the example is .. # And fill it with red $im->fill(50,50,$red); # make sure we are writing to a binary stream binmode STDOUT; # Convert the image to PNG and print it on standard output print $im->png; Nothing happens, except for some nonsense characters being displayed and the bell sounds a few times. Anybody has any idea ?
Post Follow-up to this messageOn 13 Sep 2004 13:52:39 -0700, peter <pgs@asia.com> wrote: [snip very lengthy discussion about a problem that was solved, I think] > use GD; > # create a new image > $im = new GD::Image(100,100); I prefer my $im = GD::Image->new(100, 100); You definitely need to start using strictures (and therefore the my), and I simply don't like the indirect method invocation you use. [snip] > # And fill it with red > $im->fill(50,50,$red); > # make sure we are writing to a binary stream > binmode STDOUT; > # Convert the image to PNG and print it on standard output > print $im->png; > > Nothing happens, except for some nonsense characters being displayed > and the bell sounds a few times. Anybody has any idea ? Not nonsense characters. That is your PNG image data being printed to the standard output channel of your application, just like you requested. All you need to do is capture it in a file by using your shell's redirection. If you don't want to do that (or don't know how to), then do something like (warning: untested code): open my $fh, ">", "output.png" or die "Cannot open output.png for write: $!"; binmode $fh; print $fh $im->png; close $fh; Martien -- | Martien Verbruggen | That's funny, that plane's dustin' crops Trading Post Australia | where there ain't no crops. |
Post Follow-up to this messageThanks Martien, so close and yet so far off. So it works, thanks again! Not to waste your time, but: Do you know of a simple way to constantly display the updated png's (kind of like an animation) ? > open my $fh, ">", "output.png" > or die "Cannot open output.png for write: $!"; > binmode $fh; > print $fh $im->png; > close $fh; > > Martien
Post Follow-up to this messageOn 14 Sep 2004 01:18:27 -0700, peter <pgs@asia.com> wrote: > Thanks Martien, so close and yet so far off. So it works, thanks > again! Not to waste your time, but: Do you know of a simple way to > constantly display the updated png's (kind of like an animation) ? PNG is only a single frame format, so you can't create animations with it. The MNG format would be more appropriate. You should be able to take a series of PNG images, and use Image::Magick to make an MNG animation. If you're asking how you can have a web/HTTP URL that automatically updates an image, you should probably ask that in a group that talks about HTTP protocol issues, or maybe CGI. You could simply send the appropriate header to the client that asks it to reload the image after a certain time interval, or you probably can do something with NPH (non-parsed-header) programming techniques int hat area. One of the groups in the comp.infosystems.www.* hierarchy is probably a good place to ask. Martien -- | Martien Verbruggen | There are only 10 types of people in the Trading Post Australia | world; those who understand binary and those | who don't.
Post Follow-up to this messageThanks Martien, so close and yet so far off. So it works, thanks again! Not to waste your time, but: Do you know of a simple way to constantly display the updated png's (kind of like an animation) ? > open my $fh, ">", "output.png" > or die "Cannot open output.png for write: $!"; > binmode $fh; > print $fh $im->png; > close $fh; > > Martien
Post Follow-up to this messageOn 14 Sep 2004 01:18:27 -0700, peter <pgs@asia.com> wrote: > Thanks Martien, so close and yet so far off. So it works, thanks > again! Not to waste your time, but: Do you know of a simple way to > constantly display the updated png's (kind of like an animation) ? PNG is only a single frame format, so you can't create animations with it. The MNG format would be more appropriate. You should be able to take a series of PNG images, and use Image::Magick to make an MNG animation. If you're asking how you can have a web/HTTP URL that automatically updates an image, you should probably ask that in a group that talks about HTTP protocol issues, or maybe CGI. You could simply send the appropriate header to the client that asks it to reload the image after a certain time interval, or you probably can do something with NPH (non-parsed-header) programming techniques int hat area. One of the groups in the comp.infosystems.www.* hierarchy is probably a good place to ask. Martien -- | Martien Verbruggen | There are only 10 types of people in the Trading Post Australia | world; those who understand binary and those | who don't.
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.