ExtractJPEG: Fast Command-Line Tool for Pulling JPEGs from Files

Recover JPG from Corrupted File

A corrupted JPG can often be partially or fully recovered without expensive tools. This guide gives practical, ordered steps you can follow to try recovering a damaged JPEG file, from quick checks to advanced techniques.

1. Make a safe copy

  • Do this first: Copy the corrupted file to a separate folder and work on the copy to avoid making damage worse.

2. Confirm corruption and try simple fixes

  • Open the copy with several image viewers (Photos, IrfanView, XnView, web browser). Different viewers tolerate different errors.
  • Try renaming the file extension to .jpg or .jpeg if it’s incorrect.
  • Try opening the file in an image editor (GIMP, Photoshop). Some editors can repair minor header problems.

3. Use a file-repair utility

  • Try free recovery tools that target JPEGs: JPEGsnoop (analysis), JPEG Repair Toolkit, Stellar Repair for Photo, or PhotoRec (part of TestDisk). Use one tool at a time on copies.
  • PhotoRec can often salvage image data even when headers are damaged; it recovers files by carving based on file signatures.

4. Repair the header manually (advanced)

  • JPEGs have a header with markers (SOI, APPn, SOF, DQT, DHT, SOS, EOI). If only the header is damaged and the compressed image stream exists, you can graft a good header from a known-good JPG with the same camera/settings:
    1. Obtain a working JPG shot with the same device and settings.
    2. Open both files in a hex editor (HxD, Bless).
    3. Copy the header portion from the good file up to the start of the compressed image data (look for the SOS marker 0xFFDA) and paste it into the corrupted file, leaving the corrupted file’s image data intact.
    4. Save and test. This can repair files whose headers were overwritten or truncated but where the scan data remains.

5. Recover embedded thumbnails

  • Many JPGs contain embedded thumbnails. Tools like ExifTool or Exiv2 can extract these smaller images, which may at least salvage a lower-resolution preview:
    • exiftool -b -ThumbnailImage corrupted.jpg > thumb.jpg

6. Carve the image from disk or container

  • If the file is on a failing drive or inside a larger container (ZIP, disk image), use carving tools:
    • PhotoRec or scalpel can scan raw disk images and recover JPGs by signature (FFD8…FFD9).
  • If the file was inside an archive, try extracting directly from the archive with 7-Zip or unzip; sometimes archive metadata is intact even when the file inside is corrupted.

7. Repair partial downloads or truncated files

  • If the JPG is truncated (missing EOI 0xFFD9), you can try appending a proper EOI marker; sometimes viewers then render a partial image:
    1. Append bytes FF D9 to the end using a hex editor or: printf “ÿÙ” >> file.jpg
    2. Test in viewers.

8. Use professional services as last resort

  • If images are irreplaceable and home methods fail, consider professional data-recovery services. They can be costly but have higher success on physical media failure.

9. Prevent future loss

  • Keep backups (3-2-1 rule).
  • Avoid editing originals; work on copies.
  • Regularly check storage health and replace failing drives.

Quick checklist

  • Copy file and work on the copy
  • Try multiple viewers and editors
  • Run PhotoRec or other repair tools
  • Extract embedded thumbnail with ExifTool
  • Try header grafting with hex editor (advanced)
  • Carve from disk image if needed
  • Consider professional recovery if necessary

If you want, tell me where the corrupted JPG is (local drive, SD card, archive, or cloud) and I’ll provide a tailored step-by-step command sequence for your situation.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *