This short guide explains how to create multipage TIFF in Python. It has details to set the environment, a list of steps, and a sample code to combine multiple TIFF files into one in Python, along with other types of images. You will get details to accomplish this task, from collecting input images to creating an output TIFF file with multiple pages containing individual images on each page.
Steps to Combine TIFF Files in Python
- Establish the environment to use Aspose.Imaging for Python via .NET to combine images
- Import required libraries, modules, classes, and objects
- Prepare input image files, declare variables, and create a temp folder
- Parse through each image in the collection, check its format and extract all pages if the input file is a TIFF file and store them in the collection
- Add the rest of the images to the destination images collection
- Create an output TIFF file using all the images in the collection
- Clean the resources and remove the temp folder
These steps describe how to combine TIFF files into one in Python and add other types of images as well. Commence the process by preparing the input images, checking the type of each image and adding all images to the destination collection except the TIFF files. For TIFF files, parse through all the pages in the input TIFF and extract all the pages for adding to the destination TIFF file at the end.
Code to Merge TIFF Files into One in Python
The above sample code demonstrates the process to combine TIFF files into one in Python. Each image is tested for its type, and if the loaded image is a TIFF file, its type is cast to TiffImage using the aspycore.as_of() method. It enables access to the individual pages in the input TIFF file. Otherwise, only the first page of the TIFF would be included if the TIFF file is treated as a regular image.
This article has taught us the process of combining TIFF and other types of images and creating a multipage TIFF file. To compress images such as a JPEG, refer to the article on Compress JPEG using Python.