How can I determine the length of a multi-page TIFF using Python Image Library (PIL)? -


i know image.seek() , image.tell() methods of pil allow me go particular frame, , list current frame, respectively. know how many frames there total. there function getting info? alternatively, there way in python can make loop , catch error occurs if there no image?

from pil import image videopath = '/volumes/usb20fd/test.tif' print "using pil open tiff" img = image.open(videopath) img.seek(0)  # .seek() method allows browsing multi-page tiffs, starting 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 above code open tiff stack, , access first frame. need know "how deep" stack goes don't error in downstream calculations if no image exists.

if can wait until 1st july 2015, next release of pillow (the pil fork) allow check using n_frames.

if can't wait until then, can copy implementation,patch own version, or use latest dev version.

more info here: https://github.com/python-pillow/pillow/pull/1261


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -