[MASON] Using GD for dynamic graphics

2002-03-21 Thread Nicolai Schlenzig

Hi

I would like to add some dynamic generated graphics to my site and find GD being the 
one to use. However I'm not sure _how_ to use it on my pages.

I use HTML::Mason for content management and I am very happy and truly amazed of the 
powers in Mason, but when I tried adding some GD it got me puzzled.

When I create a new GD::Image drawing whatever on it and trying to print it - it will 
be prepended to my html header for the page. I then tried to put it in $m-out to have 
in printed within Mason, but that simply printed the raw PNG in all its glory as text 
on screen.

I tried fiddeling with content_type, but I guess that wont work if I set this after I 
have already printed something on the page - hence the content_type will not even be 
effective for that page.

What I still miss doing/trying is making a seperate file/component which only job will 
be to make the PNG, but I don't really see what I would gain from that, because that 
will pretty much also just print a PNG within my HTML page.

Like:

html
head
/head
body
Some standard html text...
%perl
$m-content_type( image/png );
#my Mason/perl code for creating an image with GD.
my $image = GD::Image();
#put something on image... been using both clean GD synopsis and some home cooked 
small widgets.
print $image-png;
#or
$m-out( $image-png );
#or
$r-print( $image-png );
$m-content_type( text/html );
/%perl
Some more html text.
/body
/html

Very simplified, but I don't have my code in front of me - sorry. I would assume that 
content_type in only good for setting in the header, but I don't see how I can mix in 
this PNG then.

If GD could virtualle create a file I guess img src=% $image-png % would 
work... but that seems like a long shot when reading the man for GD :)

Any help/hints will be greatly appriciate. Maybe I just need to look harder for more 
ressources, but I've already spent a lot of time on something that looks quite simple 
- but haven't shown results yet.


Best regards

Nicolai Schlenzig
nicolai.schlenzig(at)got2get.net








Re: [MASON] Using GD for dynamic graphics

2002-03-21 Thread Dave Rolsky

On Wed, 20 Mar 2002, Nicolai Schlenzig wrote:

 When I create a new GD::Image drawing whatever on it and trying to print
 it - it will be prepended to my html header for the page. I then tried
 to put it in $m-out to have in printed within Mason, but that simply
 printed the raw PNG in all its glory as text on screen.

 I tried fiddeling with content_type, but I guess that wont work if I set
 this after I have already printed something on the page - hence the
 content_type will not even be effective for that page.

 What I still miss doing/trying is making a seperate file/component which
 only job will be to make the PNG, but I don't really see what I would
 gain from that, because that will pretty much also just print a PNG
 within my HTML page.

First of all, there's a mason users list
(http://www.masonhq.com/resources/mailing_lists.html).

Second, you don't seem to understand how images in a web page works.
When your browser sees img src=foo it makes a _seperate_ request for
foo from the web server.

The image is not somehow magically inlined in the page and served with the
request for the page itself.

What you need is a seperate top-level Mason component that generates the
image.  Use this as the value for the src attribute like img
src=foo.comp?size=2.  Then make sure that foo.comp prints the correct
headers.

And yes, you need to use $m-out, not print (this is documented in the
Mason docs).


/*==
www.urth.org
we await the New Sun
==*/