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. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin Eyles

    Parse-ing Strings

    Martin Eyles, Jan 12, 2006, in forum: ASP .Net
    Replies:
    10
    Views:
    672
    Martin Eyles
    Jan 19, 2006
  2. John

    realloc'ing an array of strings

    John, Jun 28, 2004, in forum: C Programming
    Replies:
    4
    Views:
    322
  3. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    740
    Malcolm
    Jun 24, 2006
  4. Vilmos Soti
    Replies:
    17
    Views:
    251
    Rocco Caputo
    May 9, 2004
  5. J. Sharp

    open()ing strings as filehandles

    J. Sharp, Jul 16, 2009, in forum: Perl Misc
    Replies:
    2
    Views:
    150
    Xho Jingleheimerschmidt
    Jul 17, 2009
Loading...

Share This Page