Manipulating SVG Files
Contents
[
Hide
]
Converting Image Formats into SVG
Using Aspose.Imaging for Python via .NET, developers can save different file formats to SVG. Below sample code is provided.
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
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")) |
Converting SVG into EMF
Using Aspose.Imaging for Python via .NET, developers can convert SVG file format to EMF. Below sample code is provided.
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 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")) |