[英]pillow conversion increases image size
我正在使用 python Pillow 库进行简单的图像格式转换。
这是一些简单的代码,展示了我在做什么
im = Image.open("images/filename.tiff", mode="r")
im.save("images/filename.png", optimize=True)
这导致平均增加 98% 的大小。 这是我正在尝试创建的输入 tiff 的数据:
<image mode=1 size=2544x2230>
当我显式转换它时(通过调用.convert(),大小平均只增加了 87%,但仍然很糟糕。为什么大小膨胀这么多?
这是我尝试过的?
编辑
这是一个示例图像,它贯穿了我上面描述的内容,生成了一个大 87% 的 png 文件、大 907% 的 jpeg 和大 907% 的 jpg。
https://share.getcloudapp.com/YEuR9LqP
Pillow 最新版本:8.2
Python 版本:3.8
在 MacOS 上运行:10.15.7
我是否遗漏了一些明显的东西,或者这只是我对图像库的工作原理缺乏了解?
我认为问题在于您的图像是CCITT Group4 Compressed ,它特别适合您的图像内容,并且在 PNG 格式中没有等价物。
exiftool image-1.tiff
Output
ExifTool Version Number : 12.00
File Name : image-1.tiff
Directory : .
File Size : 95 kB
File Modification Date/Time : 2021:05:17 11:46:57+01:00
File Access Date/Time : 2021:05:17 11:57:15+01:00
File Inode Change Date/Time : 2021:05:17 11:46:58+01:00
File Permissions : rw-r--r--
File Type : TIFF
File Type Extension : tif
MIME Type : image/tiff
Exif Byte Order : Little-endian (Intel, II)
Image Width : 2544
Image Height : 2230
Bits Per Sample : 1
Compression : T6/Group 4 Fax <--- HERE IT IS
Photometric Interpretation : WhiteIsZero
Strip Offsets : 180
Orientation : Horizontal (normal)
Rows Per Strip : 2230
Strip Byte Counts : 96954
X Resolution : 300
Y Resolution : 300
Resolution Unit : inches
Image Size : 2544x2230
Megapixels : 5.7
在我的 Mac 上,我从 PIL 获得了一个大小为 138,200 字节的 output PNG,即使使用pngcrush
我也只能降到 124,810 字节:
pngcrush -bruteforce result-opt.png crushed.png
Recompressing IDAT chunks in result-opt.png to crushed.png
Total length of data found in critical chunks = 138200
Best pngcrush method = 4 (ws 15 fm 0 zl 9 zs 1) = 124816
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.