I took a look at the 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,
❓ How can I split TIFF document? First, you need to add a file for split: drag & drop your TIFF file or click inside the white area for choose a file. Then click the 'Split' button. When split TIFF document is completed, you can download your result files.
tiff. A TIFF is an image file — so it stores photographic and graphical data. You won't be able to edit the original file information without editing software, like Adobe Photoshop or Illustrator.
Multi-Page Files. Some image file types can only hold a single image - for example BMP and JPEG files. Other image file types can hold multiple images - for example TIFF and DICOM files.
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
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