open()ing strings as filehandles

Discussion in 'Perl' started by J. Sharp, Jul 15, 2009.

  1. J. Sharp

    J. Sharp Guest

    Hello all,

    I'm trying to use ImageMagick to create a thumbnail from an image (JPEG) that I
    have as a string returned from an SQL query. Image::Magick->Read() will accept
    either a filename or an open file handle, so I'm opening the string as and
    passing it a reference (?) to it.

    my $immk = Image::Magick->new();

    open(FH, "<", \$image);
    $immk->Read(file => \*FH);
    close(FH);

    $immk->Thumbnail(width => THUMBNAIL_WIDTH);

    open(FH, ">", \$image);
    $immk->Write(file => \*FH, filename => 'image.jpg');
    close(FH);

    When I'm done, I expect to have the thumbnailed image in $image, but I have
    NULL! If I try this with real files, everything works fine:

    my $immk = Image::Magick->new();
    $immk->Read('/tmp/01.jpg');
    $immk->Thumbnail(width => THUMBNAIL_WIDTH);
    $immk->Write('/tmp/thumbnailed.jpg');

    I really have no clue what I'm doing wrong. Thoughts, anyone?

    Thanks.
     
    J. Sharp, Jul 15, 2009
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.