in reply to Image::Magick in Mason and STDOUT
You are right with your guess that instead of writing to the "STDOUT" of the Mason component, your $image->Write('png:-') call writes the image somewhere else.
I suppose that this is a mod_perl limitation. Are you running Mason under mod_perl?
In a terminal program or with CGI both commands "print $header_templ" and "system('cat /my/templates/header.html')" will write to the same "STDOUT", but under mod_perl this is not so.
You have two options
<%flags> inherit => undef </%flags> <%init> use Image::Magick; my $image = Image::Magick->new; $image->Set(size => '500 x 750'); $image->Read('xc:black'); STDOUT->autoflush(1); $r->content_type('image/png'); $r->send_http_header; $image->Write("png:-"); </%init>
<%flags> inherit => undef </%flags> <%init> use Image::Magick; use File::Temp; my $image = Image::Magick->new; $image->Set(size => '500 x 750'); $image->Read('xc:green'); my $temp = File::Temp->new( DIR => '/tmp', UNLINK => 1); my $temp_file_name = $temp->filename; $image->Write("png:$temp_file_name"); $r->content_type('image/png'); $r->sendfile($temp_file_name); # File::Slurp and print could be used instead of $r->sendfile # #use File::Slurp; #print read_file($temp_file_name); </%init>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Image::Magick in Mason and STDOUT
by eugeneman42 (Initiate) on Feb 03, 2011 at 00:53 UTC |