I seem to be having a problem with Image::Magick in Mason. The following code works great at a CGI script:

#!/usr/bin/perl use strict; use Image::Magick; $| = 1; my $image = Image::Magick->new; $image->Set (size => '500x750'); $image->Read ('xc:black'); print "Content-Type: image/png\n\n"; binmode STDOUT; $image->Write ('png:-'); exit 0;

Notice that I'm turning off buffering ($| = 1) and using the Write() routine to go to STDOUT.

Now, when I do this in Mason:

<%perl> use Image::Magick; $| = 1; my $image = Image::Magick->new; $image->Set (size => '500 x 750'); $image->Read ('xc:black'); $m->clear_buffer; $r->content_type ('image/png'); $image->Write ('png:-'); $m->abort; </%perl>

I get nothing sent to the browser but the header. I'm assuming that the Write() that Image::Magick is using is somehow bypassing the Mason mechanisms here. I've tried sprinkling $m->flush_buffer around too, but to no effect.

How is Mason handling STDOUT and how is Image::Magick? I'd like to see if I could get Mason working with it. Otherwise, I should be able to create a temporary .PNG and then feed it out to STDOUT manually (although I've yet to be successful creating a .PNG from Mason using Image::Magick either). But I assume that's some sort of file security problem.

THANKS for any and all hints and tips that you can provide. I know we're all very busy so it's TRULY appreciated!


In reply to Image::Magick in Mason and STDOUT by eugeneman42

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.