小编MKa*_*ana的帖子

在 Python 中计算 .TIF 文件中的总页数

我试图让 Python 准确读取 .TIF 中有多少页,并且我从昨天得到的一些帮助中修改了一些代码。我已经让 Python 读取 .TIF 文件并输出页面,但是它只读取它可以找到的第一个 .TIF 文件。我需要它来浏览同一位置的所有 .TIF 文件。

我想知道我怎样才能做到这一点,一旦完成计数,它将继续下一个文件,直到完全完成。

这是我到目前为止所拥有的

import os
from PIL import Image

count = 0
i = 0
tiffs_path = "c:\\tiftest"

for filename in os.listdir("c:\\tiftest"):
    if filename.endswith(".TIF"):
        img = Image.open(filename)
        while True:
            try:   
                img.seek(count)
                print(filename)
                print(count)
            except EOFError:
                break       
            count += 1          

print(count)
Run Code Online (Sandbox Code Playgroud)

python pillow

4
推荐指数
1
解决办法
2950
查看次数

标签 统计

pillow ×1

python ×1