githubEdit

Image File Reparing

An image sometimes is corrupeted. We can repair it using some techniques.

Check the Cause of Damage

Dump Hex from an Image

We can edit the image Hex header to repair the corrupted image to the correct format. To do that, check the hex header at first.

xxd example.jpg | head
xxd example.png | head

Using Tools

# for PNG
pngcheck example.png
# -vv: very verbosely check
pngcheck -vv example.png

Edit Hex to Adding Magic Bytes

We might be able to repair a corrupted image by inserting magic bytes for each file format. We can use hexedit or ghex to edit hex manually other than the following techniques.

To check magic bytes for each file, see wikipediaarrow-up-right.

JPG (FF D8 ...)

To repair a JPG image , run the following command. '\xff\xd8\xff\xe0\x00\x10\x4a\x46\x49\x46\x00\x01' means ‘. . . . . . JFIF . .’. It identifies JPG format.

Confirm the header repaired.

PNG (89 50 4E 47 ...)

To repair a PNG image, run the following command. '\x89\x50\x4E\x47' means ‘. PNG’. It identifies PNG format.

Confirm the header.

Last updated