Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
In this article, you will find information on how to convert SVG to PNG using Aspose.SVG for Python via .NET. Here you will find Python code examples for SVG to PNG conversion with default save options and with exactly specified conversion options. The article provides a general description of the conversion features of Aspose.SVG for python via .NET and describes supported scenarios of SVG to Image conversions by using Converter class.
You can convert SVG to images and other popular formats in any way – online or programmatically. Check the Aspose.SVG API functionality and convert SVG in real-time! Please load SVG from a local file system or URL, select the output format and run the converter. In the example, the save options are set by default. You will immediately receive the result as a separate file.
If you want to convert SVG to PNG programmatically, please see the following conversion scenarios and Python examples.
convert_svg() methodThe PNG (Portable Network Graphics) format is a widely used image format known for its lossless compression, which means it preserves all the details of an image without losing quality during compression. It supports transparency, making it ideal for web graphics, logos, and images with transparent backgrounds. PNG is popular because it offers high image quality, excellent compression ratio, and wide compatibility with various applications and web browsers. Additionally, it supports a wide range of colors and is suitable for images that require editing and resaving.
Using convert_svg() methods is the most common way to convert SVG to various popular formats. The following code snippet shows how to convert SVG to PNG with default save options:
1from aspose.svg import SVGDocument
2from aspose.svg.saving import ImageSaveOptions
3from aspose.svg.converters import Converter
4
5options = ImageSaveOptions()
6with SVGDocument("document.svg") as document:
7
8 # Convert SVG to PNG
9 Converter.convert_svg(document, options, "result.png")Aspose.SVG allows converting SVG to Image file formats using default or custom save options. ImageSaveOptions usage enables you to customize the rendering process. For example, you can specify the image format, page size, margins, background color, etc.
| Property | Description |
|---|---|
| compression | Sets Tagged Image File Format (TIFF) Compression. By default, this property is LZW. |
| css | Gets a CssOptions object which is used for configuration of CSS properties processing. |
| format | Sets the ImageFormat (JPG, PNG, BMP, TIFF, or GIF). By default, this property is PNG. |
| background_color | This property sets the color that will fill the background. By default, this property is transparent. |
| page_setup | This property allows you to define the layout of the page, including dimensions and margins. |
| horizontal_resolution | Sets the horizontal resolution for output and internal images in pixels per inch (dpi). By default, this property is set to 300 dpi, which is used unless overridden by specific conditions. The resolution is always applied unless the Page size is set in pixels (px), in which case the default resolution is 96 dpi. |
| vertical_resolution | Sets the vertical resolution for output and internal images in pixels per inch (dpi). By default, this property is set to 300 dpi, which is used unless overridden by specific conditions. The resolution is always applied unless the Page size is set in pixels (px), in which case the default resolution is 96 dpi. |
| smoothing_mode | This property sets the rendering quality for this image. |
| text | Gets a TextOptions object which is used for configuration of text rendering. |
Note: The options that are implementing with the ImageSaveOptions class are inheriting from the ImageRenderingOptions class.
The following Python example shows how to use ImageSaveOptions and convert SVG to PNG with custom save options. In addition, the following Python example will show how to configure the paths to the source and output files in your file system.
background_color property to set the color that will fill the background.page_setup property to set page size amd margins.horizontal_resolution and vertical_resolution properties to set the horizontal and vertical resolutions for output image. 1import os
2from aspose.svg import SVGDocument
3from aspose.svg.converters import Converter
4from aspose.svg.saving import ImageSaveOptions
5from aspose.svg.drawing import Resolution, Page, Size, Margin
6from aspose.pydrawing import Color
7
8# Initialize an SVG document from a file
9input_folder = "data/"
10output_folder = "output/"
11src_file = os.path.join(input_folder, "winter.svg")
12output_file = os.path.join(output_folder, "winter.png")
13if not os.path.exists(output_folder):
14 os.makedirs(output_folder)
15
16options = ImageSaveOptions()
17options.background_color = Color.from_argb(231, 217, 230)
18options.page_setup.any_page = Page(Size(600, 550), Margin(10, 10, 10, 10))
19options.horizontal_resolution = Resolution.from_dots_per_inch(96.0)
20options.vertical_resolution = Resolution.from_dots_per_inch(96.0)
21with SVGDocument(src_file) as document:
22
23 # Convert SVG to PNG
24 Converter.convert_svg(document, options, output_file)You can evaluate the quality of conversion by trying our product. Here, we provide an illustration - the following Figure shows the original winter.svg image (a) and the converted to PNG the winter.png image with a new background color (b):

You can try our free online SVG to PNG Converter that works with high quality, easy and fast. Just upload SVG, convert it, and get results in seconds! It’s fast, easy, and completely free!
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.