LinuxCommandLibrary

svg2png

Convert Scalable Vector Graphics to PNG

TLDR

Convert an SVG file to PNG

$ svg2png [path/to/file.svg] [path/to/output.png]
copy

Convert an SVG file to PNG with a specific width (preserving aspect ratio)
$ svg2png [[-w|--width]] [800] [path/to/file.svg] [path/to/output.png]
copy

Convert an SVG file to PNG with a specific height (preserving aspect ratio)
$ svg2png [[-h|--height]] [600] [path/to/file.svg] [path/to/output.png]
copy

Convert an SVG file to PNG with both width and height (image centered in space)
$ svg2png [[-w|--width]] [800] [[-h|--height]] [600] [path/to/file.svg] [path/to/output.png]
copy

Convert an SVG file to PNG scaled by a factor
$ svg2png [[-s|--scale]] [2.0] [path/to/file.svg] [path/to/output.png]
copy

Convert an SVG from stdin to PNG on stdout
$ cat [path/to/file.svg] | svg2png - - > [path/to/output.png]
copy

Flip the output image horizontally or vertically
$ svg2png --flipx [path/to/file.svg] [path/to/output.png]
copy

SYNOPSIS

svg2png [OPTIONS]

PARAMETERS

-w, --width
    Sets the width of the output PNG image in pixels.

-h, --height
    Sets the height of the output PNG image in pixels.

--scale
    Scales the SVG content by a given factor before rendering.

-q, --quality <0-100>
    Sets the PNG compression quality (lower means smaller file size but potentially lower quality).

--id
    Renders only the SVG element with the specified ID.

--background
    Sets the background color of the output PNG (e.g., 'transparent', '#RRGGBB').

-f, --force
    Overwrites the output file if it already exists.

-h, --help
    Displays a help message and exits.

-v, --version
    Outputs version information and exits.

DESCRIPTION

The svg2png command is a utility designed for converting Scalable Vector Graphics (SVG) files into Portable Network Graphics (PNG) images. This is particularly useful when you need to use vector-based graphics in contexts that do not support SVG directly, such as web pages where high performance or broader browser compatibility is required, or in applications that primarily handle raster image formats. svg2png leverages underlying libraries to interpret the SVG code and render it into a pixel-based PNG output. It offers control over output dimensions and other rendering aspects, making it a versatile tool for image format conversion in the Linux environment. The command-line interface allows for easy integration into scripts and automated workflows.

CAVEATS

The accuracy of the rendering can depend on the complexity of the SVG and the capabilities of the underlying rendering engine used by svg2png. Some advanced SVG features might not be perfectly supported. Ensure that the required rendering libraries are installed on your system.

DEPENDENCIES

svg2png typically relies on libraries like librsvg for SVG rendering. Ensure these are installed for proper functionality.

HISTORY

svg2png emerged as a need for developers and designers to bridge the gap between the flexibility of SVG and the ubiquitous support for PNG. Its development is often tied to the evolution of SVG rendering libraries in the open-source community, aiming to provide a simple, command-line interface for a common conversion task. Usage spans from web development for fallback images to generating static assets for various platforms.

SEE ALSO

convert(1), inkscape(1)

Copied to clipboard