* Pablo Velasquez <[EMAIL PROTECTED]> [2002-10-24 17:02]:
> Hi,
Hi.
> Basically, I want to dynamically generate a graph using TT and GD. Not
> a file to a /tmp folder, rather prints right to the browser.
OK.
> I can generate the graph by printing directly from Perl:
>
> print "Content-type: image/png\n\n";
> print $graph->plot($data)->png;
Yes...
> This works just fine, but I was hoping to use TT to do this. TT does
> have a plugin (Template::Plugin::GD::Graph::lines) which I tried but
> instead of the image being printed to the screen, it gets printed in
> text format.
>
> I call TT in this way:
>
> my $template = Template->new();
> print "Content-type: text/html\n\n";
> $template->process('UserPromosOutput.tpl',$vars);
Do you see the difference between your two snippets? I'm referring
primarily to the Content-type header. In the second example you're
telling the browser that you're sending html...
> The result is the expected regular html, but at the top, the png in
> text format.
...which is what it's displaying.
> The UserPromosOutput.tpl is my template which has this (the content
> type was a suggestion from the newsgroup last year):
>
> Content-Type: image/png
> [% FILTER null;
> USE g = GD.Graph.lines(300,200);
> x = [1, 2, 3, 4];
> y = [5, 4, 2, 3];
> g.set(
> x_label => 'X Label',
> y_label => 'Y label',
> title => 'Title'
> );
> g.plot([x, y]).png | stdout(1);
> END;
> -%]
Try something more like:
# Perl code
my $template = Template->new();
print "Content-type: image/png\n\n";
$template->process('UserPromosOutput.tpl',$vars)
or die $template->error;
# Template
[%
USE g = GD.Graph.lines(300,200);
x = [1, 2, 3, 4];
y = [5, 4, 2, 3];
g.set(
x_label => 'X Label',
y_label => 'Y label',
title => 'Title'
);
g.plot([x, y]).png
%]
It seems to work for me.
(darren)
--
The language Unix is vastly more inconsistent than the language Perl.
And guaranteed to remain that way, forever and ever, amen.
-- Larry Wall
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://www.template-toolkit.org/mailman/listinfo/templates