#!/usr/bin/perl -w use strict; # # Quick kludge to extract Digicam images from a file # e.g. a disk image from an accidentally erased CF card # # Scan string for the folowing markers: # SOI - Start of Image = \xff\xd8 # APP1 header for Exif = \xff\xe1 # EOI - End of Image = \xff\xd9 # # Note that the whole blob is read in memory - YYMV! # die "$0 with embedded EXIF images\n" unless (-f $ARGV[0]); my @IMGS; { open(FH, $ARGV[0]) or die $!; local $/ = undef; # Hmm... this breaks on embedded (EXIF) thumbnails... # @IMGS = split(/\xff\xd8/, ); # For EXIF only: @IMGS = split(/\xff\xd8\xff\xe1/, ); } # 1st array element contains leading crap for my $idx (1..@IMGS-1) { open(FH, sprintf("> img%02d.jpg", $idx)) or die $!; # cut crap after EOI marker print FH "\xff\xd8\xff\xe1", split(/\xff\xd9/, $IMGS[$idx], 1), "\xff\xd9"; close FH; }