A JPEG corrupted after editing or rotating is a common failure. The problem happens when a photo editor crashes while saving, or when a batch tool writes a file incorrectly. Sometimes the image is not actually broken: the app you used ignored the Exif orientation tag, making the photo look sideways or flipped. Here are the real causes and how to recover your file.
Why Saving Can Break a JPEG
Most corruption happens at the moment a file is written to disk. If your photo editor crashed while saving, the file may be half written: the data ends early, leaving the rest of the image missing. A full disk or a sudden power loss can also cause a partial save.
Editing directly on a memory card or network drive raises the risk of a partial save because the connection can drop or the card may be removed too soon. Saving over the only original removes the chance to go back; always edit a copy.
Lossless Rotation and Edge Trimming
Lossless JPEG rotation (such as jpegtran) rotates in 8x8 blocks. An image whose width or height is not a multiple of the block size may have its edge trimmed. This can make the photo look cropped or misaligned, which some users mistake for corruption. If you use a tool that performs lossless rotation, check the output dimensions before you delete the original.
The Exif Orientation Tag Confusion
Many cameras do not rotate pixels; they store an Exif orientation tag, and apps that ignore it show the photo sideways. An Exif orientation value of 1 means normal; values 3, 6 and 8 tell viewers to rotate the image 180 degrees, 90 degrees clockwise and 90 degrees counter clockwise for display.
If you see a photo that appears rotated but the file size and data seem fine, the file is not corrupted. The app you are using is simply not reading the orientation flag.
What to Do When a JPEG is Half Written
Salvaging the Readable Portion
A half written JPEG can be re encoded to keep its readable part. The readable portion is the beginning of the file up to the point where the data stops. You can often salvage the top part of the image this way. The procedure is straightforward:
- Make a copy of the damaged file so you do not lose the original.
- Open the copy in a hex editor or a plain text viewer that can handle binary data.
- Locate the last complete JPEG marker (usually FF D9). Everything after that is missing.
- Use a tool that can re encode the file from the start up to that marker, or simply delete the trailing garbage and save.
- Open the repaired file in an image viewer. You will see the portion that was saved completely.
If the file is very short and contains no image data, recovery may not be possible. In that case, the original file on your memory card or backup is the only option.
Preventing Corruption When Editing
You can avoid most save time corruption with a few habits:
- Always edit a copy of the original file. Never save over the only original.
- Save to your local hard drive first, then move the file to a memory card or network drive.
- Close other programs before saving large files to reduce the chance of a crash.
- If you use batch tools, test them on a few files first to see if they produce correct output.
- For rotation, use an editor that honors the Exif orientation tag so you do not accidentally rotate pixels unnecessarily.
Using JPEG Repair Tools
If you have a corrupted JPEG that ends early, you can try an online repair service such as jpeg.repair. These tools attempt to reconstruct the file by reading the data that was saved and discarding the missing part. The result is a viewable image, though it may be cropped or have visual artifacts at the bottom. This is better than having no image at all.