HTTP-404 has asked for the wisdom of the Perl Monks concerning the following question:

Hello guys I installed Image::Magick on my XP(win) box, when i want to output image to file, perl crashes, if i simple want to genirate image works ok, here the code i have
use Image::Magick; #$image->Quantize(colorspace=>'gray'); $image = Image::Magick->new; $image->Set(size=>'100x100'); $image->ReadImage('xc:white'); $image->Set('pixel[49,49]'=>'red'); $text = 'Dude'; $image->Annotate(font=>'test.ttf', pointsize=>40, stroke=>'green', tex +t=>$text); //Removing this section doesn't crach Perl $filename = "test.png"; open(DATA, ">$filename"); $image->Write(file=>DATA, filename=>$filename); close(DATA);
Thank You very much
  • Comment on AS Perl 629 Image::Magick makes Perl crash when outputting file to Image
  • Download Code

Replies are listed 'Best First'.
Re: AS Perl 629 Image::Magick makes Perl crash when outputting file to Image
by descartes (Friar) on Aug 29, 2001 at 16:57 UTC

    The answer to your problem is quite simple. The Image::Magic method Write, does all the file handling for you. Life will be a lot easier if you just do:

    $image->Write("format:filename");

    Don't open the file yourself, as that is most likely what is causing the module to crash your script.

    Brother Descartes

    -- Programmus, ergo sum.
Re: AS Perl 629 Image::Magick makes Perl crash when outputting file to Image
by bwana147 (Pilgrim) on Aug 29, 2001 at 12:27 UTC

    I don't know whether this would solve anything, but since you're on a windows flavour, you should switch to binary mode when outputting your picture to the file.

    And, please do check your system calls for errors.

    open(DATA, ">$filename") or die "Aargh: $!"; binmode DATA; ...

    --bwana147