> Does anyone who has/does use GD::Graph know if there's an easy way to
> embed the output graphs into HTML.
> Basically I'd like to be able to print a bunch of HTML, then the
graph,
> then some more HTML.
[WDR] The basic techniques are to either
(a) <img href="../graphs/123456789.png">
Generate the graph to a 2nd file named with a random number (for
security) or a serial number (if no security needed)
my $thisgraph; # uniq name
$this_graph = sprintf "%s/%d.png", $graphdir, rand($bignumber)
while -r $thisgraph;
print qq{<img href="$this_graph" size="$normal_size">};
put_to_file($gd->png(), $this_graph);
where put_to_file is something like (from GD::Image png method
notes)
sub put_to_file {
my ($data, $fn)[EMAIL PROTECTED];
my $fh;
open $fh, "< $fh" or die;
binmode $fh;
print $fh $data or die;
close $fh or die;
}
(b) <img
href="/scripts/imagemaker?x=17&y=42&title=%22Foo%20Bar%22&xname=X&yname=
Y">
Put the code that decides what to do from the Request in a module, and
call it from both the CGI or action module that generates the HTML page
(which generates the <img> link) and the CGI or action module that
generates the dynamic graphic (in response to the <img> link). Some
amount of setup work (varies with app) would have to be redone or saved
in DB or some other place (with unique names!), but at least the code is
reused in a module. In this case, you put all the request parameters
that the graph module needs on the IMG URI, or copy all the request
parms to be safe if you don't know; since it's a module, it should know.
One module, one script could do both Page and Image requests, with a arg
difference (or HTTP context wanting text/html or image/*?) determining
which to generate.
A has efficiency advantages in that any shared setup work for the page
and the graphic is done once.
B allows someone to statically deep link or bookmark an image.
B has efficiency advantages if page is likely to be fetched by Lynx or
WWW::Mechanize or spiders who will never fetch the image.
B has efficiency advantages if the pages will be fetched through Akamai
or client proxies, and multiple users may request the same image -- so
the image will be cached outside your server -- dont' recreate it if you
don't have to; this doesn't apply if everyone is local or every request
is unique.
etc ...
Bill n1vux
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm