Create multipage tiff from set of images
Contents
[
Hide
]
Create multipage tiff from set of images
Issue : Create multipage tiff from set of images.
Tips : To create multipage tiff from set of images add_page method can be used.
Example :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aspose.pycore as aspycore | |
from aspose.imaging import Image, RasterImage | |
from aspose.imaging.fileformats.tiff import TiffImage, TiffFrame | |
from aspose.imaging.fileformats.tiff.enums import TiffExpectedFormat | |
from aspose.imaging.imageoptions import TiffOptions | |
import os | |
if 'TEMPLATE_DIR' in os.environ: | |
templates_folder = os.environ['TEMPLATE_DIR'] | |
else: | |
templates_folder = r"C:\Users\USER\Downloads\templates" | |
delete_output = 'SAVE_OUTPUT' not in os.environ | |
data_dir = templates_folder | |
def load_images(): | |
images = [] | |
for file_path in ["template.png", "template.jpg", "template.bmp"]: | |
images.append(aspycore.as_of(Image.load(os.path.join(data_dir, file_path)), RasterImage)) | |
return images | |
# Load frames | |
images = load_images() | |
# Create TIFF image using the first frame | |
with TiffImage(TiffFrame(images[0])) as image: | |
# Add frames to the TIFF image using the AddPage method | |
for index in range(len(images)): | |
image.add_page(images[index]) | |
# Save TIFF image using options | |
options = TiffOptions(TiffExpectedFormat.TIFF_JPEG_RGB) | |
image.save(os.path.join(data_dir, "result.tiff"), options) | |
for image in images: | |
# dispose image by calling __exit__() | |
with image: | |
pass | |
if delete_output: | |
os.remove(os.path.join(data_dir, "result.tiff")) |