简体   繁体   中英

Splitting of TIF file from and to specific pages in python

Splitting of TIF file from and to specific pages in python

I am able to split multipage TIF file into pages sequential and create TIF file for each page using following python code suggested at Split .TIF file using PIL 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

My requirement is to split multipage.tif based on start and end page numbers and save it as different tif file. Eg. Create a file from page #3 to page #5 of multipage.tif. Can anyone please suggest a way to do this?

from PIL import Image
img = Image.open('multipage.tif')
frames = []
for i in range(2, 5):
    img.seek(i)
    frames.append(img.copy())
frames[0].save('output.tif', save_all=True, append_images=frames[1:])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM