Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aspose-com-gists/b41146a7e894735a6cf0274893a716a0 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/b41146a7e894735a6cf0274893a716a0 to your computer and use it in GitHub Desktop.

Aspose.Imaging for Python via .NET API allows to easy manipulate your svg images or photos in your Python application or Web service.

You can:

  • Convert svg image to another formats;
  • Create svg image;
  • Export to svg from another formats.

Interested ?

You may go further at : https://products.aspose.com/imaging/python-net/

from aspose.imaging import Image
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 Image.load(os.path.join(data_dir, "template.svg")) as image:
with open(os.path.join(data_dir, "result.svg"), "wb") as fs:
image.save(fs)
if delete_output:
os.remove(os.path.join(data_dir, "result.svg"))
import aspose.pycore as aspycore
from aspose.imaging import Image, SizeF
from aspose.imaging.imageoptions import SvgRasterizationOptions, EmfOptions
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 Image.load(os.path.join(data_dir, "template.svg")) as image:
svg_opt = SvgRasterizationOptions()
svg_opt.page_size = aspycore.cast(SizeF, image.size)
emf_opt = EmfOptions()
emf_opt.vector_rasterization_options = svg_opt
image.save(os.path.join(data_dir, "result.emf"), emf_opt)
if delete_output:
os.remove(os.path.join(data_dir, "result.emf"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment