I know that the Image.seek()
and Image.tell()
methods of PIL allow me to go to a particular frame, and list the current frame, respectively. I would like to know how many frames there are total. Is there a function for getting this info? Alternatively, is there a way in python that I can make a loop and catch for the error that occurs if there is no image?
from PIL import Image
videopath = '/Volumes/USB20FD/test.tif'
print "Using PIL to open TIFF"
img = Image.open(videopath)
img.seek(0) # .seek() method allows browsing multi-page TIFFs, starting with 0
im_sz = [img.tag[0x101][0], img.tag[0x100][0]]
print "im_sz: ", im_sz
print "current frame: ", img.tell()
print img.size()
In the above code I open a TIFF stack, and access the first frame. I need to know "how deep" the stack goes so I don't get an error in downstream calculations if no image exists.
The TIFF/IT specification (ISO 12639) describes a multiple-file format, which can describe a single page per file set. TIFF/IT files are not interchangeable with common TIFF files.
The drawings are mostly single page tiff images, but the documents may have multiple pages. For an interim fix to the issue, you will have to download a tiff viewer from the app store.
open() is used to open the image and then . width and . height property of Image are used to get the height and width of the image.
If you can wait until 1st July 2015, the next release of Pillow (the PIL fork) will allow you to check this using n_frames
.
If you can't wait until then, you can copy that implementation,patch your own version, or use the latest dev version.
More info here: https://github.com/python-pillow/Pillow/pull/1261
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With