Convert CDR to PSD in Python

Contents
[ ]

Using Python Image Processing Library - Aspose.Imaging we can convert single or multipage CDR file to Photoshop PSD file format.

The following code snippet shows you how to convert CDR to Psd.

import aspose.pycore as aspycore
from aspose.imaging import Image, Color, TextRenderingHint, SmoothingMode
from aspose.imaging.imageoptions import PsdOptions, VectorRasterizationOptions, MultiPageOptions
from aspose.imaging.fileformats.cdr import CdrImage
from aspose.imaging.fileformats.png import PngColorType
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.cdr")), CdrImage) as image:
options = PsdOptions()
# By default if image is multipage image all pages exported
options.multi_page_options = MultiPageOptions()
# Optional parameter that indicates to export multipage image as one
# layer (page) otherwise it will be exported page to page
options.multi_page_options.merge_layers = True
# Set rasterization options for file format
options.vector_rasterization_options = aspycore.as_of(
image.get_default_options([Color.white, image.width, image.height]),
VectorRasterizationOptions)
options.vector_rasterization_options.text_rendering_hint = TextRenderingHint.SINGLE_BIT_PER_PIXEL
options.vector_rasterization_options.smoothing_mode = SmoothingMode.NONE
image.save(os.path.join(data_dir, "result.psd"), options)
if delete_output:
os.remove(os.path.join(data_dir, "result.psd"))