View Full Version : Retrieving existence +height/width of image
Skeeter87
03-02-2005, 09:10 AM
Visitors of my website can post urls where their image reside, for example:
for example: http://www.europages.com/img/home/home1.jpg
How can I check if the url provided really contains a picture ? And can I retrieve the pictures height/width ?
mlseim
03-02-2005, 05:33 PM
All I could think of was using a module my webhost has installed.
But it can only display info on images on my own site (local).
This might give you some others ideas though.
==================================================
#!/usr/bin/perl
use Image::Info qw(image_info dim);
$file = "../myhouse.jpg";
my $info = image_info("$file");
if (my $error = $info->{error}) {
die "Can't parse image info: $error\n";
}
my $color = $info->{color_type};
my($w, $h) = dim($info);
print "Content-type: text/html\n\n";
print "Type: $color <br>\n";
print "Width: $w <br>\n";
print "Height: $h <br>\n";
rwedge
03-06-2005, 06:02 AM
Here is an example of putting a remote file into a subdir named temp and using Image::Magick locally to get the geometry of the image :
#!/usr/bin/perl
my $url = 'http://www.europages.com/img/home/home1.jpg';
print "Content-type: text/html\n\n";
my @in = split(/\//, $url);
my $name = pop @in;
use LWP;
my $browser = LWP::UserAgent->new;
my $response = $browser->mirror($url,"temp/$name"); die "Error at $url\n ",
$response->status_line,
"\n Aborting" unless $response->is_success;
use Image::Magick;
my $image = new Image::Magick;
$image->Read("temp/".$name);
my($w, $h)=$image->Get('width','height');
undef $image;
unlink("temp/$name");
print qq~
<b>File:</b> $url<br>
<b>Geometry:</b> $w x $h<br>
~;
Output :
File: http://www.europages.com/img/home/home1.jpg
Geometry: 406 x 246
/Bob
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.