问题描述
我正在使用python中的PIL进行项目.只需打开并保存图像,即可使输出图像比原始图像大(以字节为单位),并保持相同的分辨率,而我不知道为什么...
I´m working on a project with PIL in python.Simply by opening and saving an image makes the output image bigger (in Bytes) than the original, maintaining the same resolution, and i don´t know why...
from PIL import Image
img = Image.open("photo.png")
img.save("photo2.png", "PNG")
有人知道为什么会这样吗?我需要它们完全一样.
Does any one have any idea why this happens? i need them to be exactly the same.
推荐答案
PNG是一种压缩的无损格式.原始图像可能使用不同的压缩设置保存.
PNG is a compressed lossless format. The original image was probably saved with different compression settings.
查看文档您可以尝试:
img.save("photo2.png", "PNG", optimize=True)
或
img.save("photo2.png", "PNG", compress_level=9)
默认情况下,使用compress_level=6
.
请注意,optimize
选项包括,将压缩级别设置为9.但是,它还会尝试找到最佳的编码器设置.
Note that the optimize
option includes setting the compression level to 9. But it also tries to find optimal encoder settings.
这篇关于python PIL保存不同大小的图像原始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!