The workaround is to detect an error when there are no more images in the TIFF file:
n = 1 while True: try: img.seek(n) n = n+1 except EOFError: print "Got EOF error when I tried to load", n break;
Feel free to comment on my Python style - not quite happy with the need to do n + 1 :)
As I solved this, let's move on to the Python documentation (Errors and Exceptions). I found the correct error code debugging at the command line of Python.
>>> img.seek(1) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Python/2.7/site-packages/PIL/TiffImagePlugin.py", line 534, in seek self._seek(frame) File "/Library/Python/2.7/site-packages/PIL/TiffImagePlugin.py", line 550, in _seek raise EOFError, "no more images in TIFF file" EOFError: no more images in TIFF file >>>
source share