Ask a Question related to PERL Beginners, Design and Development.
-
Matthew Galaher #1
getting remote image size with Image::Size & LWP
Thank you for your patience and help bringing me up to speed on how to
be a better user of this list. My previous post was my first.
I am trying to write a script that will use Image::Size module in
conjunction with the LWP module to retrieve the height and width
attribute of a gif or jpg on a remote server. Below the first script
uses the Image::Size module and successfully returns the height and
width of an image on the same volume. The second script uses the LWP
module and depending on which version of $the_url is used, successfully
returns the contents of an html file or an image file. When the image
file is read it prints the "raw data" of the image file. Where I am at
a loss is how to combine these so that I can return the height & width
attributes of a remote file. Any suggestions on where I might start or
what I might try? Please bare with me while I learn how to use the list
properly. TIA
################################################## #####
#!/usr/bin/perl -w
use strict;
use Image::Size;
my $image = '/Users/mgalaher/Pictures/malden_house.jpg';
my ($globe_x, $globe_y) = imgsize($image);
print $globe_x . " " . $globe_y;
# This successfull prints the image dimensions as: 700 578
################################################## ####
#!/usr/bin/perl -w
use strict;
# to read the files via http that each url points to.
my $file = "";
my $the_url = 'http://homepage.mac.com/galaher/images/maul.jpg';
# Since printing an image just shows a huge string, test with the
following as well
# which shows an html page:
#my $the_url = 'http://homepage.mac.com/galaher/index.html';
use LWP::UserAgent; # This will cover all of them!
use URI::URL;
use HTTP::Request;
my $hdrs = new HTTP::Headers(Accept => 'text/plain', UserAgent =>
'MegaBrowser/1.0');
my $url = new URI::URL($the_url);
my $req = new HTTP::Request('GET', $url, $hdrs);
my $ua = new LWP::UserAgent;
my $resp = $ua->request($req);
if ($resp->is_success) {
# If connection is successful the contents of the file
# read will now go into the variable $file
$file = $resp->content;
}
else {
# If connection is not successful then make note of this
print $resp->message;
#$file = "socket_failure";
}
print $file;
################################################## ####
Matthew Galaher Guest
-
How to find size (in bytes) of an image using the GD image resource?
I would like to be able to determine the size (in bytes) of a file and re-adjust before output. Is this possible? Norm -- Avatar hosting at... -
getting remote image sizes with image::size lwp
I am trying to get the width and height attributes of jpg's and gif's on a remote server. I have found Image::Size and LWP but am unable to put... -
Dragging Image onto canvas changes image size
when I create a new canvas say 8.5x11, then try to drag a 4x6 size image onto it, it is not 4x6 on the canvas. it is smaller, is there a way to make... -
New Image Size?
I think it's algorithm is: if there is an image on the clipboard image size = big enough for it else image size is the last value you set it to... -
Matthew Galaher #2
Re: getting remote image size with Image::Size & LWP
I got this working. I found what I was looking for at cpan's site.
[url]http://search.cpan.org/dist/Image-Size/[/url]
works:
#!/usr/bin/perl -w
use strict;
# to read the files via http that each url points to.
my $img = "";
my $the_url = 'http://homepage.mac.com/galaher/images/maul.jpg';
# Since printing an image just shows a huge string, test with the
following as well
# which shows an html page:
#my $the_url = 'http://homepage.mac.com/galaher/index.html';
use LWP::UserAgent; # This will cover all of them!
use URI::URL;
use HTTP::Request;
my $hdrs = new HTTP::Headers(Accept => 'text/plain', UserAgent =>
'MegaBrowser/1.0');
my $url = new URI::URL($the_url);
my $req = new HTTP::Request('GET', $url, $hdrs);
my $ua = new LWP::UserAgent;
my $resp = $ua->request($req);
if ($resp->is_success) {
# If connection is successful the contents of the file
# read will now go into the variable $img
$img = $resp->content;
}
else {
# If connection is not successful then make note of this
print $resp->message;
#$img = "socket_failure";
}
use Image::Size;
# Assume that &read_data gets data somewhere (WWW, etc.)
my ($height, $width, $id) = imgsize(\$img);
print $height . " " . $width . " " . $id;
Matthew Galaher Guest



Reply With Quote

