Interesting ... this is a problem I had as well, and after looking this thread over, I've solved my problem ... which I think is the same (or very much similar) : not being able to print images on the fly, but having to write to a file first.
Here's what I gleaned from the responses that allowed my script to work:
As Michele mentions, you need to preface your lines:
binmode STDOUT;
$x = $image->Write(.png:-');
With:
print "Content-type: image/png\n\n";
And as merlyn mentioned, you must insert:
$| = 1;
so the buffer is turned off .... this buffer switch was the core of my problem, and it appears to me (and make note, I'm positioned early in the ImageMagick learning curve), that your problem is two fold ... lack of proper header and failure to turn of buffering.
The code below represents a copy of what is now working for me (on a Linux box)
#!/usr/local/bin/perl
use Image::Magick;
## turn off buffer ....
$| = 1;
my $src = Image::Magick->new;
$src->Read('bird.gif');
# Create the thumbnail, where the biggest side is 50 px
my ($thumb,$x,$y) = create($src,150);
print "Content-type: image/gif\n\n";
binmode STDOUT;
$thumb->Write('gif:-');
exit;
sub create {
my ($img,$n) = (shift,shift);
my ($ox,$oy) = $img->Get('width','height');
my $r = $ox>$oy ? $ox / $n : $oy / $n;
$img->Resize(width=>$ox/$r,height=>$oy/$r);
return $img, sprintf("%.0f",$ox/$r), sprintf("%.0f",$oy/$r);
}
Hope this helps
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.