milt95033 has asked for the wisdom of the Perl Monks concerning the following question:

Does anybody know how to take a ".jpg" file and extract the pixel dimensions of the picture? I am creating a web photo gallery and I would like to put the sizes into IMG tag to speed up loading. I'm hoping somebody can direct me to some simple code that does this, otherwise I will need to start studing the JFIF and EXIF standards I guess. --Milt--

Replies are listed 'Best First'.
Re: finding jpeg pixel size
by jdporter (Paladin) on Oct 19, 2005 at 19:53 UTC
    One way (not necessarily the best) is to use Image::MetaData::JPEG:
    use Image::MetaData::JPEG; ( $w, $h ) = Image::MetaData::JPEG->new($fname)->get_dimensions;
    We're building the house of the future together.
Re: finding jpeg pixel size
by Roy Johnson (Monsignor) on Oct 19, 2005 at 19:53 UTC
Re: finding jpeg pixel size
by terra incognita (Pilgrim) on Oct 19, 2005 at 20:03 UTC
    Use Image::Info to get the EXIF data, it is pretty simple to use and you don't need to read the standards.
    use Image::Info qw(image_info); my $width = image_info($_)->{width}; my $height = image_info($_)->{height}; print "$_\twidth = $width\theight = $height\n";
Re: finding jpeg pixel size
by milt95033 (Initiate) on Oct 20, 2005 at 12:29 UTC
    Excellent! Thanks everybody for the info. --Milt--