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;

######################################################


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to