cfreak has asked for the wisdom of the Perl Monks concerning the following question:

Okay I'm using Image::Magick to resize some images to thumbnails. I thought about using GD but I will probably be adding functions to this app later that GD can't do.

Anyway reading the original, resizing and writing the new image to a new file all works just fine but after I've done this I can no longer write to STDOUT and subsequently the webserver throws a 500 error because it doesn't receive any output from the program.

I tried selecting STDOUT ( select STDOUT) but it still didn't work. However when I did:

print STDOUT "Output blah blah ...";

It works but I feel its kind of ugly. Any ideas on being able to default back to STDOUT (am I doing something wrong?).

Here's the code in question for those interested.

my $image = Image::Magick->new; open(IMAGE,"$path") or upload_failed("Couldn't open $path for reading" +,$path); $image->Read(file=>*IMAGE); close(IMAGE); $image->Resize(width=>$conf->thumb_width,height=>$conf->th +umb_height); open(THUMB,">$thumbs/thumb_$filename") or upload_failed("Couldn't open + thumbnail file: $!",$path); $image->Write(file=>*THUMB,filenam +e=>"$thumbs/thumb_$filename"); close(THUMB); # no longer can write to STDOUT from this point on. works if # I delet +e the line $image->Write ....

Chris

Some clever or funny quote here.

Replies are listed 'Best First'.
Re: Weird problems with Image::Magick and STDOUT
by samtregar (Abbot) on May 14, 2002 at 00:14 UTC
    Try adding this after you calls to Image::Magick:

    select(*STDOUT);

    My guess is something in Image::Magick is selecting another handle. Restoring it to STDOUT should let you print again. If that is the case you might consider making a bug-report to the maintainer of Image::Magick.

    -sam

      Thank you!!! That worked. I wonder why select STDOUT (without the typeglob) didn't.

      On a totally unrelated note thank you for writting HTML::Template it makes my job so much easier :)

      Some clever or funny quote here.