如何在Python Imaging Library中调整大小调整后的图像的质量? [英] How to adjust the quality of a resized image in Python Imaging Library?

查看:745
本文介绍了如何在Python Imaging Library中调整大小调整后的图像的质量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在PIL上工作,需要知道在调整图像大小或缩略图时是否可以调整图像质量.据我所知,默认质量设置为85.在调整大小时可以调整此参数吗?

I am working on PIL and need to know if the image quality can be adjusted while resizing or thumbnailing an image. From what I have known is the default quality is set to 85. Can this parameter be tweaked during resizing?

我当前正在使用以下代码:

I am currently using the following code:

image = Image.open(filename)
image.thumbnail((x, y), img.ANTIALIAS)

ANTIALIAS参数大概可以提供最佳质量.我需要知道我们是否可以在质量选项上获得更多的详细信息.

The ANTIALIAS parameter presumably gives the best quality. I need to know if we can get more granularity on the quality option.

推荐答案

手动使用PIL的resize方法:

Use PIL's resize method manually:

image = image.resize((x, y), Image.ANTIALIAS)  # LANCZOS as of Pillow 2.7

接着是保存方法

quality_val = 90
image.save(filename, 'JPEG', quality=quality_val)

看看 <来自Photologue的c2> ,看看他们是如何做到的.

Take a look at the source for models.py from Photologue to see how they do it.

这篇关于如何在Python Imaging Library中调整大小调整后的图像的质量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆