Image Restoration code in jpg format implemented by python
This article mainly introduces the jpg Format Image repair Code implemented by python. This article provides the implementation code directly. If you need it, refer
Recently, the damaged jpg file is fixed for the customer, and the effect is acceptable, but it is not guaranteed to be applicable in any situation.
If you have damaged the photo, try it. If you can use it, leave a message for me.
The Code is as follows:
#-*-Coding: utf8 -*-
#! /Usr/bin/env python
_ Author _ = 'fengxing'
_ Date _ = '2017-1-18'
Import sys
Def jpgfix (name ):
Sig = '\ xFF \ xD8 \ xFF \ xdb'
With open (name, "r") as fd:
Fd. seek (len (sig), 0)
Jpg = fd. read ()
Pos = jpg. find (sig)
If pos <0:
Raise Exception ('not find signature ')
Jpg = jpg [pos:]
With open (name, "w") as fd:
Fd. seek (0, 0)
Print 'size is: ', len (jpg)
Fd. write (jpg)
If _ name _ = '_ main __':
Try:
While True:
Jpgfix (sys. argv [1])
Except t:
Print 'done'
The usage method is simple. Save the above Code as jpg_fix.py, and then enter
The Code is as follows:
Python jpg_fix.py ABC.jpg
ABC.jpg is the image you want to repair (Note: Back up the image before restoration)