open()ing strings as filehandles

J

J. Sharp

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top