Fetch::Image - fetch a remote image into a File::Temp
use Fetch::Image; use Try::Tiny; #or just use eval {}, it's all good my $fetcher = Fetch::Image->new( { 'max_filesize' => 524_288, 'user_agent' => 'mozilla firefox or something...', 'allowed_types' => { 'image/png' => 1, 'image/jpg' => 1, 'image/jpeg' => 1, 'image/pjpeg' => 1, 'image/bmp' => 1, 'image/gif' => 1, }, } ); my $image_info = try{ $fetcher->fetch('http://www.google.com/logos/2011/trevithick11-hp.jpg'); } catch { #error gets caught here... warn $_; #this warn $_->error; #or this }; use Data::Dumper; warn Dumper( $image_info ); #the image is now a Temp::File in $image_info->{'temp_file'};
Class that will fetch a remote image and return a hash of the image_info and the File::Temp
takes 3 options
my $fetcher = Fetch::Image->new( { 'max_filesize' => 524_288, #default value (bytes) 'user_agent' => 'mozilla firefox or something...', 'allowed_types' => { #allowed content types (default all of these) 'image/png' => 1, 'image/jpg' => 1, 'image/jpeg' => 1, 'image/pjpeg' => 1, 'image/bmp' => 1, 'image/gif' => 1, }, } );
takes 1 argument, the url of the image to fetch
returns a hash of the image info, from Data::Validate::Image, with an extra property, 'temp_file' which is the File::Temp
Mark Ellis <markellis@cpan.org>
Data::Validate::Image, File::Temp
Copyright 2014 by Mark Ellis <markellis@cpan.org>
This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.
To install Fetch::Image, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Fetch::Image
CPAN shell
perl -MCPAN -e shell install Fetch::Image
For more information on module installation, please visit the detailed CPAN module installation guide.