python - 使用 PIL 创建的多页 TIFF 图像大于单个帧
问题描述
我正在尝试对图像批次(.jpeg)进行分组,并使用 Python 和 Pillow 为每个批次创建一个多页 TIFF 文件。
使用append_images
in 中的参数save()
,我得到的文件比原始文件大得多。考虑一批 15 张 jpeg 图像(总大小 643kB),生成的 TIFF 为 6.29MB,没有压缩。
有没有办法减少文件大小,可能不使用压缩,并获得一个大小与所有原始文件相似的 TIFF 文件?
import os
from PIL import Image
sourcedir = os.getcwd()
savedir = os.path.join(sourcedir,'TIFF')
batch = ['Im-00', 'Im-01', 'Im-02', 'Im-03', 'Im-04', 'Im-05', 'Im-06', 'Im-07', 'Im-08', 'Im-09', 'Im-10', 'Im-11', 'Im-12', 'Im-13', 'Im-14']
batch_counter = 0
imlistA = []
filenameA = ["A-" + s + ".jpg" for s in batch]
for fileA in filenameA:
filepath = os.path.join(sourcedir,fileA)
imlistA.append(Image.open(filepath))
TIFFnameA = 'A-batch-0'+str(batch_counter)+'.tiff'
TIFFdirA = os.path.join(savedir,TIFFnameA)
imlistA[0].save(TIFFdirA, compression=None, save_all=True,
append_images=imlistA[1:])
解决方案
推荐阅读
- c# - 写清单
使用 System.Text.Json 到没有缩进的 Json 数组 - django - 在开发环境中本地提供 django 媒体文件
- r - nls r 中分段函数的起始值
- javascript - 使用路径字符串从另一个文件中查找文件的相对路径
- javascript - jQuery 嵌套循环
- delphi - 是否有将 DBGRID 大量数据导出为 CSV 和 XLS 的功能?
- tsql - 如何一次旋转多个值列?
- excel - 用户输入数据到图表上
- python - 使用 PyInstaller 冻结带有子命令的 Python `click` 应用程序
- ios - YPDrawSignatureView - TableView 单元格重复