Convert cmx to jpg
Contents
[
Hide
]
Using Aspose.Imaging for Python via .NET, developers can convert CMX files to Jpgimages. This topic explains the approach to load existing CMX file and convert it to Jpg.
The following code snippet shows you how to convert CMX files to Jpg.
This file contains hidden or 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, Color, TextRenderingHint, SmoothingMode | |
from aspose.imaging.imageoptions import JpegOptions, VectorRasterizationOptions | |
from aspose.imaging.fileformats.cmx import CmxImage | |
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")), CmxImage) as image: | |
options = JpegOptions() | |
# 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.jpg"), options) | |
if delete_output: | |
os.remove(os.path.join(data_dir, "result.jpg")) |