這個方法是是用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)