Looking for size bytes 05 a8 04 00 and a marker a few bytes before shows the marker to be ff c2 . Changing$ file sample.jpg sample.jpg: JPEG image data, JFIF standard 1.01, resolution (DPI), den +sity 123x123, segment length 16, progressive, precision 8, 1024x1448, + frames 3 $ perl -v This is perl 5, version 22, subversion 1 (v5.22.1) built for darwin-th +read-multi-2level $ hexdump -C sample.jpg | head -30 00000000 ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 00 7b |......JFI +F.....{| 00000010 00 7b 00 00 ff db 00 43 00 01 01 01 01 01 01 01 |.{.....C. +.......| 00000020 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 |......... +.......|* 00000090 01 01 01 01 01 01 01 01 01 01 01 01 01 01 >>>> ff c2 <<<< + |................| 000000a0 00 11 08 >>> 05 a8 04 00 <<<< 03 01 22 00 02 11 01 03 11 | +........."......| 000000b0 01 ff c4 00 1e 00 01 00 01 04 03 01 01 00 00 00 |......... +.......| 000000c0 00 00 00 00 00 00 00 06 05 07 08 09 03 04 0a 02 |......... +.......|
gives a working code set. Adding the Image::Size method to test along size giveselsif ( $_[0] =~ m/^^\xFF\xD8.{4}JFIF/s ) { $sig = 'JPEG'; # found JPG signature ($height,$width) = unpack( "nn", $1 ) if $_[0] =~ /\xFF\xC0...(....)/s; to elsif ( $_[0] =~ m/^^\xFF\xD8.{4}JFIF/s ) { $sig = 'JPEG'; ($height,$width) = unpack( "nn", $1 ) if $_[0] =~ /\xFF\xC2...(....)/s; along with the driver for my $img ( qw( ./sample.jpg ./sampleC.jpg ) ) { my $data = get_file($img); my @res = image_size($data); print "\nNative $img $res[2] width $res[0] height $res[1]\n"; ($x, $y) = imgsize($img); print "Image::Size ($x, $y)\n"
Not sure what changed or if this is just a mac thing but wanted to leave this testament for following monks.Native ./sample.jpg JPEG width 1024 height 1448 Image::Size (1024, 1448) Native ./sampleC.jpg JPEG width 617 height 1220 Image::Size (617, 1220)
In reply to Re: Image size in pure perl
by gannett
in thread Image size in pure perl
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |