这个方法是是用Python第三方图像处理库PIL(Python Imaging Library)编码的。方法非常简单,只有几行代码:
代码如下:
import PIL
from exceptions import IOError
img = PIL.Image.open("d:\\pic\\test01.jpg")
destination = "d:\\pic\\test01.jpeg"
try:
img.save(destination, "JPEG", quality=80, optimize=True, progressive=True)
except IOError:
PIL.ImageFile.MAXBLOCK = img.size[0] * img.size[1]
img.save(destination, "JPEG", quality=80, optimize=True, progressive=True)