Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Obtain image size from remote server image 1

Status
Not open for further replies.

ednit

Technical User
Jan 31, 2006
16
US
Hi,

I am trying to obtain the height and width for an image from another server before it is loaded for the user. This is for an shopping site and images over 300 width mess the page up, so I want to add the height & width tags to anything larger than 300px wide.

I am trying to use Image::Size; but it's not giving me any results. Here is my test script:

Code:
#!/usr/bin/perl

use CGI::Carp qw(fatalsToBrowser);
use Image::Size;
print "Content-type: text/html\n\n"; 

$IMAGRUL = "[URL unfurl="true"]http://domain.com/images/imagename.jpg";[/URL]

my ($IMG_WIDTH, $IMG_HEIGHT) = imgsize("$IMAGRUL");

print "$IMG_WIDTH $IMG_HEIGHT";
exit;


Like I said, I am not getting any results - I get a blank page. Also - this server is not dedicated (shared), and the script will be called on quite often - do I have to worry about resource usage should I get this working?

Thanks for any input.
 
I'm pretty sure Image::Size is for images stored on your server, not remote images. What you might have to do is use something like LWP or LWP::Simple to actually get the image, store it on your server, then use Image::Size to see what it's dims are.
 
Any instances of the Image::Size I had seen online always referred to a local file, though I couldn't find where it stated a remote one wouldn't work, but I was thinking it might not work properly for this.

Is LWP something that would be ok to run constantly (and several instances at the same time) on a shared hosting account? The site already has a lot going on(mysql+cgi), I don't want push the envelope with my resource usage.

I'll look into LWP and see what I can do with that.

Thanks for your response!
 
LWP should be OK, but you will have to check with your host and see if it's installed. Some have it, some don't. As far as using too much resources.... I don't have a clue. Let's hope not. :)
 
I do have LWP on my hosting account, but I don't have it on my local machine - I'll see if I can install LWP locally & get it working.

No, I've used the same host for 2 years now, I don't want to have to look for another cuz I crashed their servers. . .

Should I be able to get this working I'll post the code I used for it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top