带有 Image.ANTIALIAS 的 Python PIL 缩略图。如何保持质量

标签 python image python-imaging-library

我正在尝试在保持宽高比的同时调整图像大小。我为此使用 PIL 的缩略图方法。我使用 Image.ANTIALIAS 滤镜。

你可以在这里查看我的代码:

image = Image.open(design.design.path)
format = image.format
image = ImageOps.mirror(image)
new_size = (241, 241)
image.thumbnail(new_size, Image.ANTIALIAS)
image.save(response, format)

此代码工作完美,但缩略图后质量下降。我可以通过放大保存的图像来看到它。我可以在图像的角落看到像素,而在原始图像上看不到。当我打印出调整大小的图像时,效果会更好。

您可以在此处查看示例图片:http://imgur.com/a/ifZoU

如果你还需要什么请告诉我

最佳答案

Image.save 有适合你的选项:

img.save(fpath, 'image/png', quality=100, optimize=True) 

关于带有 Image.ANTIALIAS 的 Python PIL 缩略图。如何保持质量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33670251/

相关文章:

Python 的 csv、xml 和特殊字符问题

java - 为什么 java.awt.image.BufferedImage 不可序列化?

python - pip 无法安装枕头

python - 安全存储 REST API 凭据以便在 Python 环境中进行访问

python - 模拟 : assert mock_calls with a numpy array as argument raises ValueError and np. testing.assert_array_equal 不起作用

python - 在 AppEngine Python 上使用 Reportlab 生成的 PDF 文档中添加图像文件的正确方法

Python更改渐变以对角线开始

python - 在 python : Why is my circle so ugly? 中绘图

python - 出现未定义的字母?

php - 为什么图片上传到文件夹但不插入mysql数据库?