in reply to Re: Image size in pure perl
in thread Image size in pure perl

Looking at the Wiki page for jpeg I see that the size marker tag is 0xFF 0xCO for baseline images and 0xFF 0xC2 for progressive images. Also marker for a JFIF is 0xFF 0xD8 0xFF Updating complete sub image_size to ...
sub image_size { return unless $_[0]; my ($width, $height, $sig); if ( $_[0] =~ m/^GIF8..(....)/s ) { $sig = 'GIF'; # found GIF signature ($width, $height) = unpack( "SS", $1 ); } elsif ( $_[0] =~ m/^^\xFF\xD8\xFF.{3}JFIF/s ) { $sig = 'JPEG'; ($height,$width) = unpack( "nn", $1 ) if $_[0] =~ /\xFF\xC0...(....)/s; #Baseline Image ($height,$width) = unpack( "nn", $1 ) if $_[0] =~ /\xFF\xC2...(....)/s; #Pogressive Images } elsif ( $_[0] =~ /^\x89PNG\x0d\x0a\x1a\x0a/ ) { $sig = 'PNG'; # found PNG signature ($width, $height) = unpack( "NN", $1 ) if $_[0] =~ /IHDR(.{8})/s; } elsif ( $_[0] =~ /BM.{16}(.{8})/s ) { $sig = 'BMP'; # found bitmap sig ($width, $height) = unpack( "LL", $1); } return $width, $height, $sig; }