Had the same issue, and some research came up with the following code:
use strict; my $debug=0; sub readUInt8 { my ($fh) = @_; my $data; read($fh, $data, 1); return unpack("C", $data); } sub readUInt16 { my ($fh) = @_; my $data; read($fh, $data, 2); return unpack("n16", $data); } sub skipBytes { my ($fh, $len) = @_; my $data; printf(" Skipping %d bytes\n", $len) if ($debug); read($fh, $data, $len); } sub skipSection { my ($fh, $v) = @_; my $len = readUInt16($fh); skipBytes($fh, $len-2); } sub getImageInfo { my ($filename) = @_; my $v; my $fh; my $width=0; my $height=0; my $type=""; open($fh, $filename); binmode($fh); $v = readUInt16($fh); if ($v == 0xffd8) { my $done=0; while (!$done) { $v = readUInt16($fh); printf("Section %x\n", $v) if ($debug); if ($v == 0xffe0 || $v == 0xffdb || $v == 0xffe0 || $v == 0xffe1 || $v == 0xffe2 || $v == 0xffe3 || $v == 0xffe4 || $v == 0xffe5 || $v == 0xffe6 || $v == 0xffe7 || $v == 0xffe8 || $v == 0xffe9 || $v == 0xffea || $v == 0xffeb || $v == 0xffec || $v == 0xffed || $v == 0xffee || $v == 0xffc4 || $v == 0xffe0 || $v == 0xfffe ) { skipSection($fh, $v); } elsif ($v == 0xffdd) { skipBytes($fh, 4); } elsif ($v == 0xffc0) { $v = readUInt16($fh); # len $v = readUInt8($fh); # precision $height = readUInt16($fh); # width $width = readUInt16($fh); # height $type = "jpg"; last; } else { printf("$filename - Unexpected value %x\n", $v); last; } } } close($fh); return ($type, $width, $height); }

In reply to Re: getting the dimensions of a picture (jpeg) by Anonymous Monk
in thread getting the dimensions of a picture (jpeg) by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.