【问题标题】:Adjust the quality of a resized PNG image in PIL在 PIL 中调整调整大小的 PNG 图像的质量
【发布时间】:2018-07-31 10:56:34
【问题描述】:

无论我做什么来降低PNG图像的质量,这都不会改变文件大小,它似乎对我不起作用,我如何使用质量参数来降低质量并因此降低文件大小图片的,请参阅下面的代码。

请注意,原始图像类型是 JPEG。

将下面的质量从 100 更改为 0 没有任何作用。

代码:

basewidth = 400
im = Image.open(path+item)
try:
    for orientation in ExifTags.TAGS.keys():
        if ExifTags.TAGS[orientation]=='Orientation':
            break
    exif=dict(im._getexif().items())

    if exif[orientation] == 3:
        im=im.rotate(180, expand=True)
    elif exif[orientation] == 6:
        im=im.rotate(270, expand=True)
    elif exif[orientation] == 8:
        im=im.rotate(90, expand=True)
    im.save(path+item)

except:
    print "exception"
    pass
im = add_corners(im, 180)
f, e = os.path.splitext(path+item)
wpercent = (basewidth/float(im.size[0])) 
hsize = int((float(im.size[1])*float(wpercent))) 
imResize = im.resize((basewidth,hsize), Image.ANTIALIAS)
imResize.save(f + '.png', format="PNG", quality=10, optimize=True)

【问题讨论】:

  • PNG 格式没有“质量”,因为它是无损格式。可能该参数被用于 compression 质量 - 查看 PIL 手册。

标签: python image png python-imaging-library reduce


【解决方案1】:

我最终使用了 compress_level

imResize.save(f + '.png', format="PNG", compress_level=5)

也可以使用以下optimize=True

【讨论】:

    猜你喜欢
    • 2012-12-01
    • 2014-02-17
    • 2021-02-15
    • 2010-11-27
    • 1970-01-01
    • 2011-01-24
    • 1970-01-01
    • 1970-01-01
    • 2017-04-01
    相关资源
    最近更新 更多