Python - 将两个 Tif 文件附加到特定文件中

Python - Appending of two Tif files into specific file

Python - 将两个 TIF 文件附加到特定文件

我的要求是将两个单页 TIF 文件附加到具有两页的单个 TIF 文件中。我知道存在 append_images 参数并尝试按如下方式实现它:

img1 = Image.open(open("file1.tif", 'rb'))
img2 = Image.open(open(“file2.tif", 'rb'))
img1.seek(0)
img1.save(output.tif,save_all=True,append_images=img1)

以上代码生成 TypeError: TiffImageFile' object is not iterable.

任何人都可以建议一种将两个文件附加到单个文件的方法吗?

因为append_images需要数组,试试:

img1.save(output.tif,save_all=True,append_images=[img1])

希望对您有所帮助!