Click here to get back home

Mixing HTML::Template and GD::Graph

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Mixing HTML::Template and GD::Graph Colin Walls 05-14-2005
Posted by Colin Walls on May 14, 2005, 8:53 am
Please log in for more thread options


I have developed an application using CGI::Application and HTML::Template.
Some of the run modes in the application use GD:Graph to present charts.

In the GD:Graph documentation they simply write graphical information to
STDOUT to present the information to a web page. I can't work out whether
this is possible using HTML::Template, and if it is, how to do it. As a
result I am writing the charts to a file and using a standard image tag in
my template file.

Is it possible to write present a GD:Graph chart without writing a file in
this scenario?

--
Colin Walls
Removed the pink meat to mail me


Posted by Sherm Pendley on May 14, 2005, 4:58 am
Please log in for more thread options


Colin Walls wrote:
> I have developed an application using CGI::Application and HTML::Template.
> Some of the run modes in the application use GD:Graph to present charts.
>
> In the GD:Graph documentation they simply write graphical information to
> STDOUT to present the information to a web page. I can't work out whether
> this is possible using HTML::Template, and if it is, how to do it. As a
> result I am writing the charts to a file and using a standard image tag in
> my template file.
>
> Is it possible to write present a GD:Graph chart without writing a file in
> this scenario?

Yes, but probably not in the way you're thinking. There's no getting
around the fact that the user agent will be making a second, entirely
separate request for the image data. So you can't print the image and
HTML as part of the same request.

What you can do is, within the HTML::Template CGI, construct an img
element whose src attribute points to a second CGI that prints the
image, and includes in the query string any parameters that one will
need to do its job.

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


Posted by Ignoramus4744 on May 14, 2005, 1:41 pm
Please log in for more thread options


As someone else said, the browser makes a separate request for files
anyway.

I use GD::Graph on my site a lot. I use it for drawing cute math
formulas.

For example, I could plot a formula x[1,2] = (-b+-sqrt( b^2-4ac ) )/2a
and it would be painted, you can play with it at

http://www.algebra.com/services/rendering/

It is done without writing to files. Note declaration my $jpeg and
print $jpeg. (as a complication, these jpegs are saved into my binary
cache MySQL table for future reuse).

sub main() {
my $jpeg;

print $cgi->header(-type=>'image/jpeg', -expires=>'+1d');

# try to look up the binary cache right away!
my $formula_id = "formula: $expr";

my $use_cache = 1;

if( $use_cache ) {
$jpeg = retrieve_item_from_binary_cache( $formula_id );

if( defined $jpeg ) {
print $jpeg;
return;
}
}
$full_expr = $expr;
#print STDERR "$0: Rendering '$expr'.\n";
my $parsed = create_parsed_expression( $expr );

my $im;
if ( !$global_error ) {
calculate_sizes( $parsed );
$im = paint( $parsed );
} else { # error
$im = paint_error_message( $global_error );
}

if ( $cgi->param( "cross" ) ) {
$im->line( 0, 0, $parsed->, $parsed->, $red );
$im->line( 0, $parsed->, $parsed->, 0, $red );
}
$jpeg = $im->jpeg( 70 );
print $jpeg;

store_item_in_binary_cache( $formula_id, "formula", $jpeg );



Similar ThreadsPosted
HTML::Template March 5, 2008, 2:40 pm
HTML::template September 12, 2008, 10:52 am
HTML::Template and __ODD__ July 22, 2005, 7:48 am
HTML::Template not outputting February 25, 2008, 3:11 pm
Namespace for new module: HTML::Template::HTX? May 13, 2005, 7:17 pm
HTML::Template arbitraryily nested recursive loops April 8, 2005, 2:59 pm
HTML::Template, is it possible to nest inside a ? June 4, 2007, 4:58 pm
install HTML::Template - Problem reading cache file / Bad file number July 24, 2004, 7:55 pm
Mixing subclasses December 29, 2006, 6:39 pm
GD::Graph - how to get rid of leading gap in line graph? October 1, 2004, 10:56 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap