Convert SVG to Raster image
Convert SVG to Raster image
Using Aspose.Imaging for Python via .NET, developers can convert SVG (Scalable Vector Graphics) to raster formats. This article shows how to export/convert SVG file to raster image formats with Aspose.Imaging. Aspose.Imaging for Python via .NET provides the SvgImage class to load SVG files and same can be used to convert the SVG to raster formats.
import aspose.pycore as aspycore | |
from aspose.imaging import Image | |
from aspose.imaging.imageoptions import PngOptions, 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.svg")) as image: | |
options = PngOptions() | |
svg_options = SvgRasterizationOptions() | |
svg_options.page_width = 100.0 | |
svg_options.page_height = 200.0 | |
options.vector_rasterization_options = svg_options | |
image.save(os.path.join(data_dir, "result.png"), options) | |
if delete_output: | |
os.remove(os.path.join(data_dir, "result.png")) |
import aspose.pycore as aspycore | |
from aspose.imaging import Image | |
from aspose.imaging.imageoptions import BmpOptions, 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.svg")) as image: | |
options = BmpOptions() | |
svg_options = SvgRasterizationOptions() | |
svg_options.page_width = 100.0 | |
svg_options.page_height = 200.0 | |
options.vector_rasterization_options = svg_options | |
image.save(os.path.join(data_dir, "result.bmp"), options) | |
if delete_output: | |
os.remove(os.path.join(data_dir, "result.bmp")) |