import aspose.pycore as aspycore
from aspose.imaging import Image, Color, Rectangle
from aspose.imaging.imageoptions import WmfRasterizationOptions, PngOptions
from aspose.imaging.fileformats.wmf import WmfImage
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
# Load an existing WMF image
with aspycore.as_of(Image.load(os.path.join(data_dir, "template.wmf")), WmfImage) as image:
	image.crop(Rectangle(0, 0, 100, 100))
	# Create an instance of WmfRasterizationOptions class and set different properties
	wmf_rasterization = WmfRasterizationOptions()
	wmf_rasterization.background_color = Color.white_smoke
	wmf_rasterization.page_width = 1000.0
	wmf_rasterization.page_height = 1000.0
	# Create an instance of PngOptions class and provide rasterization option
	image_options = PngOptions()
	image_options.vector_rasterization_options = wmf_rasterization
	# Call the save method, provide output path and PngOptions to convert the cropped WMF file to PNG and save the output
	image.save(os.path.join(data_dir, "result.png"), image_options)

if delete_output:
	os.remove(os.path.join(data_dir, "result.png"))