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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Image::Size

Status
Not open for further replies.

salewit

Programmer
Oct 31, 2002
58
US
I'm a novice Perl user trying to get the width and height attributes of some Jpegs. I found this demo site with the following code:

#!/usr/bin/perl -w
use strict;
use Image::Size;

# Just fetch the size
my ($size_x, $size_y) = Image::Size::imgsize("test.jpg");
print "Image is: $size_y x $size_x (height x width)\n";

# HTML-friendly format
my $size = Image::Size::html_imgsize("test.jpg");
print &quot;Here is my image <img src=\&quot;test.jpg\&quot; $size>\n&quot;;

exit();

At first I put the code in my actual program, and I got nothing but:

Image is: x (height x width)

Then I took the above example and changed the test.jpg to a known path to a jpeg file. First I got a 500 error, and then I added:

print &quot;Content-type:text/html\n\n&quot;;

and again all I got was:

Image is: x (height x width)

The path to the jpeg is 100% correct, and I checked our Perl modules on the server and it lists Image::Size as being there.

Any ideas?

Thanks
Sam
 
I have used this module many times, and have never had a problem with it. If the path is definitely correct, then it might be file permissions. If the script doesn't access to the image file, then that could stop it getting any results.

Are you passing an absolute or relative path, or is the image in the same directory that your script is running? Also is this running on Linux or Windows, or another OS?

Barbie
Leader of Birmingham Perl Mongers
 
I've tried this module a time or two without any success but I did get the size to properly display while using Image::Info instead. If you're still having problems, maybe you should check that out.

&quot;Age is nothing more than an inaccurate number bestowed upon each of us at birth as just another means for others to judge and classify us- sulfericacid
 
I've tried:

my ($size_x, $size_y) = Image::Size::imgsize(&quot;
and I've tried:

my ($size_x, $size_y) = Image::Size::imgsize(&quot;../test.jpg&quot;);

and I've tried:

$jpegimage = &quot;my ($size_x, $size_y) = Image::Size::imgsize($jpegimage);

I haven't tried the non-url path, but I'll do that now and see what happens.

Is it possible that my host doesn't have this module installed even though they show it as being installed? In other words, wouldn't I get an error if it tried to access a module that didn't exist?

Thanks
Sam
 
Well thanks for tipping me off in the right direction. I got it now. It required a non-url type address (i.e. /home/domain/public_html/images/test.jpg).

Works fine now.
 
Same thing with Image::Info, the image has to have the right permissions for YOU to read it otherwise it will refuse to open it (which generally means it has to be on your server).

&quot;Age is nothing more than an inaccurate number bestowed upon each of us at birth as just another means for others to judge and classify us- sulfericacid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top