7 GetOptions(dumpall => \$dumpall,
8 "e|exif=s" => \$exiffile);
11 or die "Usage: $0 filename\n";
13 open my $fh, "<", $file
14 or die "$0: cannot open '$file': $!\n";
21 unless (read($fh, $chead, 2) == 2) {
22 eof $fh or die "Failed to read start of chunk: $!";
25 if ($chead eq "\xFF\xD8") {
26 print "Start of image\n";
28 elsif ($chead =~ /^\xFF[\xE0-\xEF]$/) {
31 unless (read($fh, $clen, 2) == 2) {
32 die "Couldn't read length for APPn\n";
34 my $len = unpack("S>", $clen);
36 unless (read($fh, $appdata, $len-2) == $len-2) {
37 print "length ", length $appdata, " expected $len\n";
38 die "Couldn't read application data for APPn\n";
40 if ($chead eq "\xFF\xE0") {
42 my $type = substr($appdata, 0, 5, '');
43 print "APP0 ", $type =~ tr/\0//dr, "\n";
44 if ($type eq "JFIF\0") {
45 my ($version, $units, $xdens, $ydens, $tx, $ty, $rest) =
46 unpack("S>CS>S>CCa*", $appdata);
47 printf " Version: %x\n", $version;
48 print " Units: $units\n";
49 print " Density: $xdens x $ydens\n";
50 print " Thumbnail: $tx x $ty\n";
56 elsif ($chead eq "\xFF\xE1") {
58 if ($appdata =~ s/^Exif\0.//) {
61 open my $eh, ">", $exiffile
62 or die "Cannot create $exiffile: $!\n";
66 or die "Cannot close $exiffile: $!\n";
72 die "I don't know how to handle ", unpack("H*", $chead), "\n";
78 jpegdump.pl - dump the structure of a JPEG image file.
82 perl jpegdump.pl [-dumpall] [-exif=exifdata] filename
86 Dumps the structure of a JPEG image file.
94 C<-dumpall> - dump the entire contents of each chunk rather than just
95 the leading bytes. Currently unimplemented.
99 C<< -exif I<filename> >> - extract the EXIF blob to a file.
103 This is incomplete, I mostly wrote it to extract the EXIF blob, but I
104 expect I'll finish it at some point.