Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Use SVGDocument to load an SVG file, create ImageSaveOptions, set the image format, and call Converter.convert_svg(document, options, output_path). Use ImageSaveOptions to control the background color, page size, margins, and output resolution.
| API | Purpose |
|---|---|
| SVGDocument | Loads the source SVG document |
| Converter.convert_svg() | Converts SVG to raster image formats |
| ImageSaveOptions | Configures image output for converter-based workflows |
| ImageRenderingOptions | Configures image output for device-based rendering workflows |
| ImageDevice | Receives rendered SVG content and writes an image file |
| ImageFormat | Selects the target image format |
Aspose.SVG for Python via .NET can convert SVG documents to raster image formats such as JPG, BMP, TIFF, GIF, and PNG. Use JPG when transparency is not required, PNG for transparent raster output, TIFF for publishing and image-processing workflows, BMP for simple bitmap output, and GIF for lightweight raster output.
For a PNG-focused tutorial, see Convert SVG to PNG in Python. This article focuses on the broader SVG-to-image workflow and format selection.
Before running the examples, install Aspose.SVG for Python via .NET in your Python environment.
The following example converts an SVG file to JPG and sets a custom background, page size, margins, and resolution. JPG does not support transparency, so setting a background color is usually important.
1import os
2from aspose.svg import SVGDocument
3from aspose.svg.converters import Converter
4from aspose.svg.drawing import Margin, Page, Resolution, Size
5from aspose.svg.rendering.image import ImageFormat
6from aspose.svg.saving import ImageSaveOptions
7from aspose.pydrawing import Color
8
9# Convert SVG to JPG with custom background, page size, and resolution
10input_folder = "data/"
11output_folder = "output/"
12input_path = os.path.join(input_folder, "christmas-tree.svg")
13output_path = os.path.join(output_folder, "christmas-tree.jpg")
14os.makedirs(output_folder, exist_ok=True)
15
16options = ImageSaveOptions()
17options.format = ImageFormat.JPEG
18options.background_color = Color.from_argb(233, 255, 241)
19options.page_setup.any_page = Page(Size(450, 450), Margin(20, 20, 20, 20))
20options.horizontal_resolution = Resolution.from_dots_per_inch(96.0)
21options.vertical_resolution = Resolution.from_dots_per_inch(96.0)
22
23with SVGDocument(input_path) as document:
24 Converter.convert_svg(document, options, output_path)The following image shows the source SVG and the converted JPG result with a custom background color.

To save SVG as another image format, set options.format and use the matching file extension. For example, use ImageFormat.GIF with .gif, ImageFormat.BMP with .bmp, or ImageFormat.TIFF with .tiff.
1options.format = ImageFormat.GIF
2output_path = os.path.join(output_folder, "image.gif")| Property | What it controls |
|---|---|
| format | Target image format such as JPG, PNG, BMP, TIFF, or GIF |
| background_color | Background color for transparent SVG areas |
| page_setup | Output image size, margins, and page layout |
| horizontal_resolution | Horizontal output resolution in pixels per inch |
| vertical_resolution | Vertical output resolution in pixels per inch |
| smoothing_mode | Rendering quality for shapes and edges |
| compression | TIFF compression settings |
ImageSaveOptions inherits image rendering settings from
ImageRenderingOptions, so many output properties are shared between converter-based and device-based workflows.
The render_to() method sends SVG content to an image rendering device. This pattern is useful when your application already uses rendering devices or needs to select the target device explicitly.
1import os
2from aspose.svg import SVGDocument
3from aspose.svg.drawing import Margin, Page, Resolution, Size
4from aspose.svg.rendering.image import ImageDevice, ImageFormat, ImageRenderingOptions
5
6# Render SVG to JPG through an ImageDevice
7input_folder = "data/"
8output_folder = "output/"
9input_path = os.path.join(input_folder, "image.svg")
10output_path = os.path.join(output_folder, "image.jpg")
11os.makedirs(output_folder, exist_ok=True)
12
13options = ImageRenderingOptions()
14options.format = ImageFormat.JPEG
15options.horizontal_resolution = Resolution.from_dots_per_inch(96.0)
16options.vertical_resolution = Resolution.from_dots_per_inch(96.0)
17options.page_setup.any_page = Page(Size(600, 600), Margin(10, 10, 10, 10))
18
19with SVGDocument(input_path) as document:
20 with ImageDevice(options, output_path) as device:
21 document.render_to(device)| Problem | Likely cause | Fix |
|---|---|---|
| JPG output has a black or unexpected background | JPG does not support transparency | Set options.background_color before conversion |
| The output image is cropped or too large | Page setup does not match the SVG viewport or desired output size | Configure page_setup.any_page with Page, Size, and Margin |
| The image is blurry | Output resolution or page size is too low | Increase horizontal_resolution, vertical_resolution, or output dimensions |
| The wrong format is produced | The image format and file extension do not match | Set both options.format and the output file extension deliberately |
| External images or CSS are missing | Relative resources cannot be resolved during conversion | Keep resources next to the SVG file or use correct absolute paths |
Use the free online SVG to JPG Converter or the general SVG Converter to test SVG-to-image conversion before implementing it in Python.
Load the SVG with SVGDocument, set ImageSaveOptions.format to ImageFormat.JPEG, and call Converter.convert_svg(document, options, output_path).
Yes. Change options.format to the required ImageFormat value and use the matching output file extension.
JPG does not support transparency. A background color makes transparent SVG areas predictable in the converted image.
Yes. Configure options.page_setup.any_page with a Page, Size, and Margin, and set the resolution if needed.
Use Converter.convert_svg() for ordinary file conversion. Use render_to() when you need a rendering-device workflow with ImageDevice.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.