Convert cmx to tiff

Contents
[ ]

Using Aspose.Imaging we can convert single paged or multi-page cmx image to single or multi-page tiff.

The following code snippet shows you how to convert cmx to tiff.

import aspose.pycore as aspycore
from aspose.imaging import Image, VectorMultipageImage, SizeF
from aspose.imaging.imageoptions import TiffOptions, CmxRasterizationOptions, MultiPageOptions
from aspose.imaging.fileformats.cmx import CmxImage
from aspose.imaging.fileformats.tiff.enums import TiffExpectedFormat
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
with aspycore.as_of(Image.load(os.path.join(data_dir, "template.cmx")), VectorMultipageImage) as image:
page_options = []
for page in image.pages:
option = CmxRasterizationOptions()
option.page_size = aspycore.cast(SizeF, page.size)
page_options.append(option)
# Create TIFF options
multi_page_options = MultiPageOptions()
multi_page_options.page_rasterization_options = page_options
options = TiffOptions(TiffExpectedFormat.TIFF_DEFLATE_RGB)
options.multi_page_options = multi_page_options
# Export image to TIFF format
image.save(os.path.join(data_dir, "result.tiff"), options)
if delete_output:
os.remove(os.path.join(data_dir, "result.tiff"))