これを行う 1 つの方法を次に示します。必要に応じて微調整します。
import clr
clr.AddReference("System.Drawing")
from System.Drawing import Image
from System.Drawing.Imaging import FrameDimension
from System.IO import Path
# sourceFilePath - The full path to the tif image on disk (e.g path = r"C:\files\multipage.tif")
# outputDir - The directory to store the individual files. Each output file is suffixed with its page number.
def splitImage(sourceFilePath, outputDir):
img = Image.FromFile(sourceFilePath)
for i in range(0, img.GetFrameCount(FrameDimension.Page)):
name = Path.GetFileNameWithoutExtension(sourceFilePath)
ext = Path.GetExtension(sourceFilePath)
outputFilePath = Path.Combine(outputDir, name + "_" + str(i+1) + ext)
frameDimensionId = img.FrameDimensionsList[0]
frameDimension = FrameDimension(frameDimensionId)
img.SelectActiveFrame(frameDimension, i)
img.Save(outputFilePath, ImageFormat.Tiff)