Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

image sizes (not local)

by Anonymous Monk
on Jun 25, 2006 at 16:33 UTC ( #557442=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Is there a module that can determine the dimensions of an image based on a URL to the image?

Replies are listed 'Best First'.
Re: image sizes (not local)
by sulfericacid (Deacon) on Jun 25, 2006 at 18:14 UTC
    The only way I can think of is using LWP::Simple to getstore($location, $storepic) and then traverse the directory of images and size them. Afterwards delete all the images.


    "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

    sulfericacid
Re: image sizes (not local)
by rblasch (Monk) on Jun 25, 2006 at 18:13 UTC

    How about this: Download the image into a scalar and determine the image size from there.

    #!/usr/bin/perl use strict; use warnings; use LWP::Simple; use Image::Size; my $url = 'YOUR URL HERE'; my $img = get($url); my ($width, $height) = imgsize(\$img); print "$url is ${width}x${height}\n";

      Just out of curiousity I used your snippet but I can't get it to work. Are you sure you can get() and image and determine it's size without first storing it?


      "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

      sulfericacid

        I used your snippet but I can't get it to work.

        The problem is with line 43b.

        Are you sure you can get() and image and determine it's size without first storing it?

        Quote Image::Size 3.0: "If the passed-in stream is a scalar reference, it is interpreted as pointing to an in-memory buffer containing the image data."

Re: image sizes (not local)
by jdtoronto (Prior) on Jun 25, 2006 at 18:00 UTC
    Nope, using Image::Size will need to be used in conjunction with something that actually downloads the image. That will tell you what size the image file is, not what size a html page will display it at.

    jdtoronto

Re: image sizes (not local)
by TedPride (Priest) on Jun 25, 2006 at 17:36 UTC
      Nope.

      "If an ordinary scalar (string) is passed, it is assumed to be a file name (either absolute or relative to the current working directory of the process) and is searched for and opened (if found) as the source of data. Possible error messages (see DIAGNOSTICS below) may include file-access problems." I need it to be sized as a URL argument, not a path.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://557442]
Approved by davido
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (1)
As of 2022-01-20 05:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (56 votes). Check out past polls.

    Notices?