Convert CDR to PNG in Python

Contents
[ ]

Using Python Image Processing Library Aspose.Imaging we can convert CDR image to PNG.

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

import aspose.pycore as aspycore
from aspose.imaging import Image, Color, TextRenderingHint, SmoothingMode
from aspose.imaging.imageoptions import PngOptions, VectorRasterizationOptions
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 = PngOptions()
options.color_type = PngColorType.TRUECOLOR_WITH_ALPHA
# 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.png"), options)
if delete_output:
os.remove(os.path.join(data_dir, "result.png"))
view raw cdr-to-png.py hosted with ❤ by GitHub