Using GD on the fly to add a graph to a web page
[email protected] (bacoms) Mon, 2 Feb 2009 05:26:59 -0800 (PST)
| Newsgroups | perl.beginners.cgi |
|---|---|
| Organization | http://groups.google.com |
| Message-ID | <c4c05310-c9f8-416c-ab29-ae88ba877d8a@r10g2000prf.googlegroups.com> |
I've got a web page that includes a graph. I achieve this with code
that looks like:
print "Content-type: text/html\n\n";
etc
etc
my($myImage) = $myChart->plot(\@data) or die $myChart->error;
open(IMAGE, ">Images/zzzgraph.png") or die $!;
binmode IMAGE;
print IMAGE $myImage->png;
close IMAGE;
print " <img src='Images/zzzgraph.png' width='800'
height='600'>\n";
Is it possible to eliminate the need to first write the image to
disk?
All my attempts at trying this have all failed. The best I get is with
the following code:
print "Content-type: text/html\n\n";
etc
etc
my($myImage) = $myChart->plot(\@data) or die $myChart->error;
print $myImage->png;
which produces gibberish where the chart should be. (cribbed from
http://linuxgazette.net/issue83/padala.html )
I suspect is that this specifies "Content-type: image/png\n\n" whereas
my web page specifies "Content-type: text/html\n\n".
I've tried specifying both content-types on my web page but this
results on the user being asked if they want to save the script
(??????).
Can it be done and how????
Thanks,
Bryan