Hi --

I am trying to generate dynamic pngs with Mason, like the photo gallery article on perl.com.

I'm trying to get the simple bits working before folding in the full application logic, so for now, I'm just trying to use a dhandler to server a red square for any file requests ending in .png in a certain directory. (That directory has no real png files.)

The dhandler looks like this:

<%shared> return unless $r->uri =~ /\.png$/; # die "made it here!"; use GD; my $image = new GD::Image(100, 100); my $red = $image->colorAllocate( 255, 0, 0); $image->filledRectangle( 25, 25, 75, 75, $red); $m->clear_buffer; $r->content_type('image/png'); $m->print($image->png); $m->abort(200); </%shared>
and the directory in question is set to use Mason on .png files.

The dhandler is running, as I can reach the die message (by uncommenting that line).

But no image is displayed: firefox displays the file name requested (whatever.png); IE shows a broken image.

The related Mason book example on "generating something besides html" mentions  $r->send_http_header, which I seems to be an Apache1.x-ism. I'm using Apache 2, which I suspect is relevant. The Apache2.x docs seem to imply that  $r->send_http_header isn't necessary, that is, that just calling  $r->content_type is sufficient.

In short, I'm not getting my red square.

I am not sure if my error is Mason or Apache or what.

Any ideas, wise monks?

Thanks!

water


In reply to Generating pngs with Mason by water

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.