Textual Wmf to Png conversion in Python
Contents
[
Hide
]
Support textual Wmf to Png conversion
Issue : When converting WMF file to PNG, the text position and style can change.
Tips : It is necessary to change the RenderMode property to AUTO in WmfRasterizationOptions.
Example :
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, SizeF | |
from aspose.imaging.imageoptions import WmfRasterizationOptions, PngOptions | |
from aspose.imaging.fileformats.wmf import WmfRenderMode | |
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 | |
file_name = "template.wmf" | |
input_file_name = os.path.join(templates_folder, file_name) | |
output_file_name = input_file_name + ".png" | |
with Image.load(input_file_name) as image: | |
obj_init = WmfRasterizationOptions() | |
obj_init.render_mode = WmfRenderMode.AUTO | |
obj_init.page_size = aspycore.cast(SizeF, image.size) | |
rasterization_options = obj_init | |
obj_init2 = PngOptions() | |
obj_init2.vector_rasterization_options = rasterization_options | |
image.save(output_file_name, obj_init2) | |
if delete_output: | |
os.remove(output_file_name) |