Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Extracting a blob from DBI to a buffer

by haj (Vicar)
on Oct 30, 2019 at 19:30 UTC ( [id://11108132]=note: print w/replies, xml ) Need Help??


in reply to Extracting a blob from DBI to a buffer

Unfortunately, Image::Epeg-new(\$jpg_data); isn’t working.
What makes you write that? I'm too lazy to whip up a database, but the following code pulls a JPEG image into a scalar and thumbnails it successfully.
use 5.020; use warnings; use Image::Epeg qw(:constants); use LWP::Simple; # Copyright notice for the image: # By Randal Schwartz from Portland, OR, USA - Flickr, CC BY-SA 2.0, # https://commons.wikimedia.org/w/index.php?curid=2938351 my $image = get("https://upload.wikimedia.org/wikipedia/commons/b/b3/L +arry_Wall_YAPC_2007.jpg"); die "Failed to load the image" unless defined $image; my $epeg = Image::Epeg->new(\$image); $epeg->resize(150,150,MAINTAIN_ASPECT_RATIO); $epeg->write_file("thumbnail.jpg");
Side note: You need to have LWP::Protocol::https installed for this code.

Replies are listed 'Best First'.
Re^2: Extracting a blob from DBI to a buffer
by Serene Hacker (Initiate) on Oct 31, 2019 at 19:26 UTC
    Thanks everyone!

    OK, Image::Epeg-new(\$jpg_data); does work. The $epg->resize function fails occasionally -- even though they're valid jpegs and larger than the crop size. (And the call is more likely to fail, the larger the crop size). And $epg->get_data occasionally fails (sticking exactly 64k zeroes at the beginning of the data, and then ever larger amounts of junk (?) on the end) -- even though resize returned 1.

    There's not much point in posting code yet. I'm still trying to figure out if there's anything wrong with the input files. Or whether there's something wrong with my installation -- or even the hardware! Anyway -- whatever's going on, it has nothing to do with extracting a blob from DBI. :-)

    I'm running perl 5.28.2 on Mac OS X 10.14.6 with MacPorts. I recently re-installed Xcode (and the command line tools, and MacPorts and Perl etc.) -- a software update to Xcode had changed some directories to from 10.14 to 10.15 (!) Some builds still fail (arm-none-eabi-gdb in MacPorts, and Image::Magick in CPAN) soooo, not sure what (if anything) is wrong...If I manage to narrow things down to a nice test I'll start a different thread.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11108132]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-19 11:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found