Need to get the size of an image on the web without storing it. Done by pulling the image with LWP::Simple and giving the content buffer to Image::Size.
#!/usr/bin/perl
# Get dimensions of web image
# 04/17/2009 WR
use strict;
use warnings;
use LWP::Simple;
use Image::Size;
my @urls = (
"http://www.google.com/intl/en_ALL/images/logo.gif",
"http://l.yimg.com/a/i/ww/beta/y3.gif",
"http://www.example.com/nothing.gif",
"http://graphics8.nytimes.com/images/misc/nytlogo379x64.gif",
);
URL:
for my $url (@urls) {
my $image = get $url;
unless (defined $image) {
warn "Couldn't get $url!\n";
next URL;
}
my ($width, $height) = imgsize(\$image);
printf "%4d %4d %s\n", $width, $height, $url;
}
exit 1;

Leave a comment