# -*- coding: utf8 -*-
# !/usr/bin/env python
__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,再从命令行里输入
网友评论
文明上网理性发言,请遵守 新闻评论服务协议我要评论