优化后的PIL库增加了图像大小

我正在编写一个使用python的PIL库优化图像的脚本。但这恰恰相反。我做了什么:

import os
import sys
from PIL import Image

def compressMe(file,verbose=False):
    filepath = os.path.join(os.getcwd(),file)
    oldsize = os.stat(filepath).st_size
    picture = Image.open(filepath)
    dim = picture.size

    picture.save("Compressed_"+file,"JPEG",optimize=True,quality=85,progressive=True) 

    newsize = os.stat(os.path.join(os.getcwd(),"Compressed_"+file)).st_size
    percent = (oldsize-newsize)/float(oldsize)*100
    if (verbose):
        print("File compressed from {0} to {1} or {2}%".format(oldsize,newsize,percent))
    return percent

def main():
    verbose = False
    #checks for verbose flag
    if (len(sys.argv)>1):
        if (sys.argv[1].lower()=="-v"):
            verbose = True

    #finds present working dir
    pwd = os.getcwd()

    tot = 0
    num = 0
    for file in os.listdir(pwd):
        if os.path.splitext(file)[1].lower() in ('.jpg','.jpeg'):
            num += 1
            tot += compressMe(file,verbose)
    print("Average Compression: %d" % (float(tot)/num))
    print("Done")

if __name__ == "__main__":
    main()

不幸的是,它给了我以下结果,使图像的尺寸增加了16%。

How do we control web page caching,across all browsers?

谢谢。

jacod2980 回答:优化后的PIL库增加了图像大小

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2958949.html

大家都在问