Gossamer Forum
Home : General : Perl Programming :

Image::Size?

Quote Reply
Image::Size?
I have just installed the Image::Size library, and it won't work for my desired purpose.

I run a bulletin board. Users can add images to their post by entering the specific command and the url location of the img file. Obviously, some folks post up images that are too big for 800x600 resolution screens. My desire is to view the image height and width attributes and then determine whether I need to hardcode smaller attributes so that the images won't run off the screen.

Using the Image::Size library, I have no problem checking the attributes on local files (files on my own server). But, it won't work for image files on outside servers.

Is there a way to do this?

Thanks...

Rob (www.rrbbs.com)
Quote Reply
Re: [rrbbsguy] Image::Size? In reply to
A quick glance at the docs shows that there is no support for passing in a URL to the image. However, it does have the ability to work on a buffer, so you could just fetch the image yourself and then process it. Something like:

Code:
#!/usr/local/bin/perl -w
use strict;
use LWP::Simple;
use Image::Size;

my $image = get('http://www.example.com/images/sample.jpg');
my ($x, $y) = imgsize(\$image);

print "Width is $x\nHeight is $y\n";

Be warned though, if someone decides to do something like give the url to a 2G image, you could have a problem as the above will attempt to fetch the whole image. It could result in some disk swapping (performance), or it could result in memory issues.

So, you'd be best to check the size of the image before retrieveing it (I'll leave that as an exericse for you)

--mark