Skip to content

Instantly share code, notes, and snippets.

@aspose-com-kb
Last active August 30, 2024 17:06
Convert Image to SVG in Python. For more details: https://kb.aspose.com/imaging/python/convert-image-to-svg-in-python/
import aspose.imaging
from aspose.imaging import Image
from aspose.imaging.fileformats.png import PngImage
from aspose.imaging.imageoptions import SvgOptions, SvgRasterizationOptions
import os
path = "C://"
with Image.load(os.path.join(path, "input.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(path, "result.svg"), svg_options)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment