Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Quick Answer: To convert SVG to JPG in Python, load the source file with
SVGDocument, create
ImageSaveOptions, set
options.format = ImageFormat.JPEG, and call
Converter.convert_svg(document, options, output_path). Set a background color because JPG does not support transparency.
JPG is useful when you need a compact raster preview, thumbnail, report image, or web asset and transparency is not required. If the SVG contains transparent areas, choose an explicit background color before conversion. Otherwise the final background may depend on the renderer or viewing workflow.
Before running the examples, install Aspose.SVG for Python via .NET in your Python environment.
The following example loads document.svg, selects JPEG output, and saves the result as document.jpg.
1from aspose.svg import SVGDocument
2from aspose.svg.converters import Converter
3from aspose.svg.rendering.image import ImageFormat
4from aspose.svg.saving import ImageSaveOptions
5
6# Convert an SVG file to JPG
7options = ImageSaveOptions()
8options.format = ImageFormat.JPEG
9
10with SVGDocument("document.svg") as document:
11 Converter.convert_svg(document, options, "document.jpg")The example uses SVGDocument to load the source file, ImageSaveOptions with ImageFormat.JPEG to select JPG output, and Converter.convert_svg() to write the converted file.
Use ImageSaveOptions when the JPG needs a specific canvas, background, or resolution. The next example sets a light background, creates a 450 x 450 page with margins, and renders at 96 dpi.
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, "flower.svg")
13output_path = os.path.join(output_folder, "flower.jpg")
14os.makedirs(output_folder, exist_ok=True)
15
16options = ImageSaveOptions()
17options.format = ImageFormat.JPEG
18options.background_color = Color.from_argb(240, 240, 240)
19options.page_setup.any_page = Page(Size(350, 350), Margin(10, 10, 10, 10))
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 an SVG source (a) and the converted JPG result (b) with a custom background color.

| Property | When to use it |
|---|---|
| format | Select JPEG output with ImageFormat.JPEG |
| background_color | Fill transparent SVG areas before saving to JPG |
| page_setup | Set page dimensions, margins, and canvas layout |
| horizontal_resolution | Set horizontal output resolution in dpi |
| vertical_resolution | Set vertical output resolution in dpi |
| smoothing_mode | Control rasterization quality for shapes and edges |
| Problem | Likely cause | Fix |
|---|---|---|
| JPG output has a black or unexpected background | The source SVG has transparent areas, but JPG cannot store transparency | Set options.background_color before conversion |
| The image is blank or cropped | The SVG has no usable viewport, or the output page is smaller than the visible content | Define SVG width, height, or viewBox, or configure options.page_setup.any_page |
| Linked images, CSS, or fonts are missing | Relative resources cannot be resolved from the current input path | Load the SVG from its original file path and keep linked resources in the expected relative locations |
| The file extension and actual format do not match | options.format was not set to ImageFormat.JPEG, or the output path uses the wrong extension | Set options.format = ImageFormat.JPEG and save to .jpg or .jpeg |
| Lines, icons, or text look jagged | The output dimensions or raster resolution are too low for the target display size | Increase page dimensions or resolution, and check smoothing_mode for quality-sensitive output |
Use the free online SVG to JPG Converter to test output before implementing the same workflow in Python.
Load the SVG with SVGDocument, set ImageSaveOptions.format to ImageFormat.JPEG, and call Converter.convert_svg(document, options, output_path).
Use JPG for compact previews, thumbnails, and web images when transparency is not required. Use PNG when you need lossless raster output or transparent areas.
No. JPG is a raster image format. After conversion, the output contains pixels, not editable SVG elements, paths, or text nodes.
Yes. Use ImageFormat.JPEG and choose either .jpg or .jpeg in the output file name, depending on the naming convention your workflow expects.
Yes. Create an SVGDocument from a URL, file stream, or SVG markup string with a valid base URI, then pass the document to Converter.convert_svg() with JPEG image options.
Yes. Loop through the input folder, use the same ImageSaveOptions, and call Converter.convert_svg() for each SVG file. See
Batch Convert SVG Files.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.