Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > open()ing strings as filehandles

Reply
Thread Tools

open()ing strings as filehandles

 
 
J. Sharp
Guest
Posts: n/a
 
      07-16-2009
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.

 
Reply With Quote
 
 
 
 
Uri Guttman
Guest
Posts: n/a
 
      07-16-2009
>>>>> "JS" == J Sharp <(E-Mail Removed)> writes:

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

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

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

there you have a single arg as the filename. above you have both a
handle AND a filename. try dropping the filename as it isn't needed. you
want it to write to the string handle only. the docs show both args for
a write call which makes no sense. so i bet the docs are in error.

$image->Write(file=>\*IMAGE, filename=>$filename);

in fact if it can detect a handle vs a filename you may just be able to
pass the handle by itself (no key) and it may work. a single arg seems
to be assumed the file or filename. worth trying anyhow.

uri

--
Uri Guttman ------ http://www.velocityreviews.com/forums/(E-Mail Removed) -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
 
Reply With Quote
 
 
 
 
Xho Jingleheimerschmidt
Guest
Posts: n/a
 
      07-17-2009
J. Sharp wrote:
> 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);


Image::Magick is a wrapper around C code. I don't know exactly where
the boundaries of this wrapper are, but it is Perl-unaware C code doing
the reading and writing, then Perl's magic filehandles aren't going to work.

Xho
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 5.9 How can I make a filehandle local to a subroutine? How do I pass filehandles between subroutines? How do I make an array of filehandles? PerlFAQ Server Perl Misc 0 01-12-2011 11:00 PM
open()ing strings as filehandles J. Sharp Perl 0 07-15-2009 08:16 PM
Strings, Strings and Damned Strings Ben C Programming 14 06-24-2006 05:09 AM
FileHandles to string Andrew Perl 1 07-10-2004 06:00 PM
newbie - Output to multiple Filehandles Jeremy Phillips Perl 1 05-25-2004 01:38 AM



Advertisments