时间:2021-07-01 10:21:17 帮助过:89人阅读
如果你有损坏照片,不妨试一试,如果可以使用给我留个言哦。
__author__ = 'fengxing'
__date__ = '2012-1-18 20:13'
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:
print 'Done'
使用方法很简单,上面代码另存为jpg_fix.py,再从命令行里输入