Split .TIF file using PIL
Question: I took a look at the [Split multi-page tiff with
python](http://stackoverflow.com/questions/9627652/split-multi-page-tiff-with-
python) file for Splitting a .TIFF File, however to be honest, I didn't fully
understand the answers, and I'm hoping for a little clarification.

I am attempting to take a .Tif file with multiple Invoices in it and Split it
into each page which will then be Zipped Up and uploaded into a database. PIL
is installed on the computers that will be running this program, as such I'd
like to stick with the PIL Library. I know that I can view information such as
the Size of each Image using PIL after it's open, however when I attempt to
Save each it gets dicey. (Example Code Below)

    
    
    def Split_Images(img,numFiles):
        ImageFile = Image.open(img)
        print ImageFile.size[0]
        print ImageFile.size[1]
        ImageFile.save('InvoiceTest1.tif')[0]
        ImageFile.save('InvoiceTest2.tif')[1]
    

However when I run this code I get the following Error:

    
    
    TypeError: 'NoneType' object has no attribute '__getitem__'
    

Any Suggestions?

Thank you in advance,


Answer: You need the PIL Image "seek" method to access the different pages.

    
    
    from PIL import Image
    
    img = Image.open('multipage.tif')
    
    for i in range(4):
        try:
            img.seek(i)
            img.save('page_%s.tif'%(i,))
        except EOFError:
            break
    

