首页 > 解决方案 > 使用 PIL 创建的多页 TIFF 图像大于单个帧

问题描述

我正在尝试对图像批次(.jpeg)进行分组,并使用 Python 和 Pillow 为每个批次创建一个多页 TIFF 文件。

使用append_imagesin 中的参数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:])

标签: pythonpython-imaging-librarytiff

解决方案


推荐阅读