You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用PIL将TIFF转PDF后文件体积暴涨20倍的问题求助

TIFF转PDF体积暴增问题排查

我曾尝试调整density参数但毫无效果——原始TIFF图片仅459 kB,转换为PDF后体积骤增至8446 KB。起初我以为是这段通过subprocess调用Magick convert的代码导致的:

commands = ['magick', 'convert']
commands.extend(waiting_list["images"][2:])
commands.append('-adjoin')
commands.append(combinedFormPathOutput)
process = Popen(commands, stdout=PIPE, stderr=PIPE, shell=True)
process.communicate()

但后来排查发现问题并非出自这段代码,而是源于下面的PIL转换代码:

images = []
filepath = 'Multi_document_Tiff.tiff'
image = Image.open(filepath)
   
if filepath.endswith('.tiff'):
        imagepath = filepath.replace('.tiff', '.pdf')
        for i, page in enumerate(ImageSequence.Iterator(image)):
            page = page.convert("RGB")
            images.append(page)
        if len(images) == 1:
            images[0].save(imagepath)
        else:
            images[0].save(imagepath, save_all=True, append_images=images[1:])
        image.close()

内容的提问来源于stack exchange,提问作者parth prasad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 08:48:21