Functions

Convenience functions for the common “render this SVG to a PNG file” case, and for reading the library version.

import novasvg

novasvg.svg2png("input.svg", "output.png")
print(novasvg.__version__)

Reference

svg2png(input_data, output_path, width=-1, height=-1, background_color=0, css=None)[source]

Renders an SVG source to a PNG file.

Parameters:
  • input_data (str | bytes | Path | IOBase) – The SVG source: a file path (str/Path), raw data (str/bytes), or a file-like object.

  • output_path (str | Path) – Where to save the PNG image.

  • width (int) – Output width in pixels. -1 (default) auto-scales from the SVG’s intrinsic size.

  • height (int) – Output height in pixels. -1 (default) auto-scales from the SVG’s intrinsic size.

  • background_color (int | Color) – A packed 0xAARRGGBB integer or a novasvg.Color. Defaults to fully transparent.

  • css (str | None) – Optional CSS rules to apply to the document before rendering.

Raises:
  • FileNotFoundError – If the input file does not exist.

  • ValueError – If the SVG content is invalid or cannot be rendered.

  • IOError – If the output file cannot be written.

Return type:

None

version_string() → str

Get the library version as a string (e.g., ‘0.1.0’).