Professional Web Applications Themes

getting remote image sizes with image::size lwp - PERL Beginners

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 them together so that I can open an http path (e.g. [url]http://wwwfoobar.com/dirname/dirname/dirname/images/111203.gif[/url]) and print out the image size. Any help would be appreciated including where I might go to read more on this. TIA My first attempt that failed: #!/usr/bin/perl # The next few lines use the LWP (Library www perl) module # to read the files via http that each url points to. $the_url = 'http://wwwfoobar.com/dirname/dirname/dirname/images/111203.gif'; use LWP::UserAgent; # This ...

  1. #1

    Default 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 them together so
    that I can open an http path (e.g.
    [url]http://wwwfoobar.com/dirname/dirname/dirname/images/111203.gif[/url]) and
    print out the image size. Any help would be appreciated including where
    I might go to read more on this. TIA

    My first attempt that failed:

    #!/usr/bin/perl
    # The next few lines use the LWP (Library www perl) module
    # to read the files via http that each url points to.
    $the_url =
    'http://wwwfoobar.com/dirname/dirname/dirname/images/111203.gif';
    use LWP::UserAgent; # This will cover all of them!
    use URI::URL;
    use HTTP::Request;
    $hdrs = new HTTP::Headers(Accept => 'text/plain',
    User-Agent => 'MegaBrowser/1.0');

    $url = new URI::URL($the_url);
    $req = new HTTP::Request(GET, $url, $hdrs);
    $ua = new LWP::UserAgent;
    $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
    $image = $resp->content;

    }
    else {

    # If connection is not successful then make note of this
    #print $resp->message;
    $image = "socket_failure";
    $sf_exists = "true";
    }

    use Image::Size;
    ($globe_x, $globe_y) = imgsize($image);
    print $globe_x . " " . $globe_y;

    

    Matthew Galaher Guest

  2. #2

    Default Re: getting remote image sizes with image::size lwp

    Matthew Galaher wrote:
    > 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 them together so
    > that I can open an http path (e.g.
    > [url]http://wwwfoobar.com/dirname/dirname/dirname/images/111203.gif[/url]) and
    > print out the image size. Any help would be appreciated including where
    > I might go to read more on this. TIA
    >
    > My first attempt that failed:
    [snip--not yet relevant]

    Please show us the code and results when you:

    Test Image::Size in isolation, using a local image file of known properites. Include any error
    messages, the clearly marked lines they refer to, and a description of what happens or doesn't when you
    run it.

    Make sure you have:
    use strict;
    use warnings;
    at the top of your script. People are usually not willing to spend much time on you problem until you
    do.

    Test LWP in isolation, getting a known plain text file and reading out the contents. Include any error
    messages, the clearly marked lines they refer to, and a description of what happens or doesn't when you
    run it.

    Make sure you have:
    use strict;
    use warnings;
    at the top of your script. People are usually not willing to spend much time on you problem until you
    do.

    Joseph



    R. Joseph Newton Guest

Similar Threads

  1. Replies: 6
    Last Post: July 31st, 11:05 AM
  2. adjusting image sizes
    By vorpal in forum Macromedia Flash Actionscript
    Replies: 0
    Last Post: January 19th, 09:29 PM
  3. getting remote image size with Image::Size & LWP
    By Matthew Galaher in forum PERL Beginners
    Replies: 1
    Last Post: November 13th, 11:27 PM
  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. different monitors, different image sizes?
    By rjacobsen in forum Macromedia Dreamweaver
    Replies: 6
    Last Post: July 18th, 06:36 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