in reply to Image::Magick and outputting to browser
With:binmode STDOUT; $x = $image->Write(.png:-');
And as merlyn mentioned, you must insert:print "Content-type: image/png\n\n";
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)$| = 1;
Hope this helps#!/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); }
|
---|