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
|