Professional Web Applications Themes

getting remote image size with Image::Size & LWP - PERL Beginners

 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 ...

  1. #1

    Default 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

  2. #2

    Default 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

Similar Threads

  1. Replies: 6
    Last Post: July 31st, 11:05 AM
  2. getting remote image sizes with image::size lwp
    By Matthew Galaher in forum PERL Beginners
    Replies: 1
    Last Post: November 13th, 03:06 PM
  3. image size for Web
    By Chuck Snyder in forum Adobe Photoshop Elements
    Replies: 0
    Last Post: September 4th, 02:59 AM
  4. Dragging Image onto canvas changes image size
    By Brian Ingle in forum Adobe Photoshop 7, CS, CS2 & CS3
    Replies: 1
    Last Post: August 26th, 03:22 PM
  5. Image size
    By Max Goodwin in forum Adobe Photoshop Elements
    Replies: 6
    Last Post: August 10th, 12:42 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139