Recovering digital camera images from media

If you have a corrupt or accidentally reformatted CF card or some other media from a digital camera, and you need to recover images from it, I recommend you try some real software designed to do that. PhotoRescue™ is one, and I Lexar Media sells something too, and there are others. I have not tried them (yet), so I don't know how well they work. If you lost some images, and you don't want to pay for something, and you like playing around with applescripts, you could try this.

I made this script because I forgot to drag a CF card to the trash before I pulled it out of my CF card reader. Then I put it back in, and it was still mounted on the desktop, so the images put on the card in the meantime were lost. I knew the images were still actually (mostly) on the card, but the Mac couldn't see them. So I looked at the format of jpegs and saw that they all seem to start with FF D8 FF and end with FF D9. I made this script to look for those patterns and try to write out any possible jpegs. jpgs aren't necessarily written contiguously by the camera, and old ones can be partially overwritten, so the script looks for the beginning of a jpeg, and then writes till it comes to the next beginning. That way you tend to get a bunch of extra junk on the end, but most jpeg readers (including PhotoShop and the wonderful Cameraid) will read a jpeg and ignore extra junk at the end. In fact, last time I checked, Cameraid would truncate them if you rotate or optimize or transform them to tidy up the files and get rid of extra junk on the end. Photoshop seems to be particularly good at partially reading corrupt jpegs, so sometimes you can recover parts of an image which has been partially overwritten (but don't count on it). It's probably not worth the extra effort though, unless it's a really important image, or you are just curious to try it. If you're really desperate, I recommend trying every jpeg reader you can get your hands on, Cameraid, Photoshop, ImageMagick, Quicktime, etc. as they seem to have different tolerances for different kinds of corruption.

With that script, I tend to get the thumbnails of the images which are the previews embedded in the EXIF data, and also the images themselves. This is sometimes useful because thumbnails are smaller and therefor less likely to be partially overwritten, but I wanted to try to recover some images with the EXIF data intact (including the time the picture was taken if the camera's clock is set), so I made a similar version which looks for EXIF data as the beginning of a file to recover. This can also recover some raw camera formats which contain EXIF data.

I made this script in OS9, and I may have modified it to work in OSX, and I haven't tried it in OS9 in a while, so I'm not sure if it will work in OS9 without some modification. I'm not even sure it will work on any particular OSX system, so use it at your own risk, and good luck.

The first step is to make an uncompressed image of the CF card (or whatever media). The media is a DOS format, and the Apple "Disk Copy" utility can make a disk image of it (Image from Device (OS X) or Image from Disk (OS 9)). Make it uncompressed, not encrypted, and preferably Read Only. This will make an exact copy of the whole volume, even if there appear to be no files on it. You'll end up with a .img or .dmg file. Run the script, choose the disk image file and a place to try to write the jpegs, and it will churn away (it's pretty slow). I have it "say" things as it progresses, if you have speech off, disable those parts, and you can make it display dialogs or something if you want.

Applescript to Recover JPEGs from CF card script

Applescript to Recover JPEGs (JPG or other format) from CF card using EXIF markers


applescript page