• 照片的压缩率在80%时,不影响照片质量
import os,sys
from PIL import Image

def compress_image(infile, outfile='', to_quality=80):
    #o_size = os.path.getsize(infile)
    #print(o_size)
    im = Image.open(infile)
    #(w, h) = im.size 
    im.save(outfile, quality=to_quality)

if __name__ == '__main__':
    compress_image('f1.jpg','a1-1.jpg')