Convert Raster Image to SVG

Convert Raster Image to SVG

Using Aspose.Imaging for Python via .NET, developers can convert Raster image to SVG. This article shows how to export/convert Raster format file to SVG formats with Aspose.Imaging. Using Aspose.Imaging for Python via .NET you can load image of any format and than you can set various properties using SvgImage class and save the image. The following code snippet shows you how to convert SVG to PNG image.

from aspose.imaging import Image
from aspose.imaging.fileformats.png import PngImage
from aspose.imaging.imageoptions import SvgOptions, SvgRasterizationOptions
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.png")) as image:
svg_options = SvgOptions()
svg_rasterization_options = SvgRasterizationOptions()
svg_rasterization_options.page_width = float(image.width)
svg_rasterization_options.page_height = float(image.height)
svg_options.vector_rasterization_options = svg_rasterization_options
image.save(os.path.join(data_dir, "result.svg"), svg_options)
if delete_output:
os.remove(os.path.join(data_dir, "result.svg"))