Convert Vector Image to Vectorized PSD Image in Python

Convert vector image to vectorized psd image

Issue : How to convert vector image to vectorized psd image.

Tips : Starting from 22.3 release Aspose.Imaging library supports conversion of vector images to vectorized psd image.

Example of conversion vector image to vectorized psd image

import aspose.pycore as aspycore
from aspose.imaging import Image
from aspose.imaging.fileformats.psd import VectorDataCompositionMode
from aspose.imaging.imageoptions import PsdVectorizationOptions, PsdOptions, VectorRasterizationOptions
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
# The path to the documents directory.
data_dir = templates_folder
input_file_name = os.path.join(data_dir, "template.cmx")
# Export vector image to PSD format keeping vector shapes
# Aspose.Imaging allows to export vector image formats such as CDR, EMF, EPS, ODG, SVG, WMF to the PSD format,
# while keeping vector properties of the original, utilizing PSD Shapes, Paths //and Vector Masks.
# Currently, export of not very complex shapes is supported, whithout texture brushes or open shapes with stroke,
# which will be improved in the upcoming releases.
# Example
# Export from the CDR format to the PSD format preserving vector
# properties is as simple as the following snippet:
with Image.load(input_file_name) as image:
obj_init = PsdVectorizationOptions()
obj_init.vector_data_composition_mode = VectorDataCompositionMode.SEPARATE_LAYERS
obj_init2 = PsdOptions()
obj_init2.vector_rasterization_options = VectorRasterizationOptions()
obj_init2.vectorization_options = obj_init
image_options = obj_init2
image_options.vector_rasterization_options.page_width = float(image.width)
image_options.vector_rasterization_options.page_height = float(image.height)
image.save(os.path.join(data_dir, "result.psd"), image_options)
if delete_output:
os.remove(os.path.join(data_dir, "result.psd"))