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

In reply to Re: Image::Magick and outputting to browser by Hagbone
in thread Image::Magick and outputting to browser by wil

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.