How can I use IO::Scalar with Image::Magick::Read()?

后端 未结 2 1506
一生所求
一生所求 2021-01-14 05:19

I have an image I have manipulated with GD::Image and I want to do further manipulations with Image::Magick. I\'d like to avoid writing the image out to disk just so Image:

2条回答
  •  离开以前
    2021-01-14 06:15

    From the docs...

    To read an image in the GIF format from a Perl filehandle, use:

    $image = Image::Magick->new;
    open(IMAGE, 'image.gif');
    $image->Read(file=>\*IMAGE);
    close(IMAGE);
    

    So... I think a reference to your filehandle (\$FH) in your example, instead of just the filehandle, should do the trick?

    Edit: To respond to brian d foy, this is what I was suggesting trying:

    my $image = Image::Magick->new;
    open my $fh, 'image.gif';
    binmode $fh;
    $image->Read( file => \$fh );
    close $fh;
    

    On my system, at least, this seg faults.

    I'll let this post stand as an example of what doesn't work. :P

提交回复
热议问题