最近为客户修复损坏的jpg写的,效果还可以,但不保证适用任何情况。
如果你有损坏照片,不妨试一试,如果可以使用给我留个言哦。
复制代码 代码如下:
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'
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8