
rsvg Command in Linux
rsvg is a Linux command line tool designed for converting and rendering SVG (Scalable Vector Graphics) files into various raster image formats, such as PNG, JPEG, and ICO. This command is a part of the librsvg library and allows users to handle SVG graphics efficiently. This makes it a valuable resource for web developers, graphic designers, and anyone involved in creating or processing image files.
Table of Contents
Here is a comprehensive guide to the options available with the rsvg command −
- Installing of rsvg Command
- Syntax of rsvg Command
- rsvg Command Options
- Examples of rsvg Command in Linux
Installing of rsvg Command
To use the rsvg command, you first need to install the librsvg package. Here's how you can do it on different Linux distributions −
For Debian / Ubuntu-based systems
sudo apt install librsvg2-bin
For Red Hat/CentOS-based systems
sudo yum install librsvg2-tools
For Fedora-based systems
sudo dnf install librsvg
For Alpine Linux
sudo apk add librsvg
For Arch Linux
sudo pacman -S librsvg
Syntax of rsvg Command
The basic syntax for the rsvg command is −
rsvg-convert [options] input.svg -o output.png
Where,
- [options] − These are optional flags that modify the behavior of the rsvg command.
- input.svg − This is the path to the SVG file that you want to convert.
- -o output.png − This specifies the output file and its format. Replace output.png with your desired output filename and format.
rsvg Command Options
Listed below are few different options that can be used with the command rsvg on Linux −
Option | Description |
---|---|
-a, --keep-aspect-ratio | Preserve the aspect ratio of the original SVG. |
-b, --background-color <color> | Set the background color using a CSS color specification (default: none). |
--completion <completion> | Generate shell completion scripts (possible values: bash, elvish, fish, powershell, zsh). |
-d, --dpi-x <number> | Set the horizontal DPI (dots per inch) of the output image (default: 96). |
-f, --format <format> | Specify the output format (possible values: png, pdf, pdf1.7, pdf1.6, pdf1.5, pdf1.4, ps, eps, svg). |
-h, --height <length> | Specify the height of the output image (default: height of the SVG). |
-i, --export-id <object-id> | Export a specific SVG object by its ID (default: export all objects). |
--keep-image-data | Preserve image data. |
-l, --accept-language <languages> | Specify languages to accept (e.g., "es-MX,de,en"; default: environment language). |
--left <length> | Define the distance between the left edge of the page and the image (default: 0). |
--no-keep-image-data | Do not preserve image data. |
-o, --output <output> | Specify the output filename (default: stdout). |
--page-height <length> | Set the height of the output media (default: height of the SVG). |
--page-width <length> | Set the width of the output media (default: width of the SVG). |
-p, --dpi-y <number> | Set the vertical DPI of the output image (default: 96). |
-s, --stylesheet <filename.css> | Apply a CSS stylesheet. |
--top <length> | Define the distance between the top edge of the page and the image (default: 0). |
-u, --unlimited | Allow processing of large SVG files. |
-v, --version | Show the version information of rsvg. |
-w, --width <length> | Specify the width of the output image (default: width of the SVG). |
-x, --x-zoom <number> | Set the horizontal zoom factor. |
-y, --y-zoom <number> | Set the vertical zoom factor. |
-z, --zoom <number> | Set a uniform zoom factor for both dimensions. |
Examples of rsvg Command in Linux
Here are some practical examples to demonstrate how to use the rsvg command −
- Converting to JPEG
- Converting SVG to PNG
- Preserving Aspect Ratio
- Setting DPI
- Specifying Width and Height
Converting to PNG
If you want to convert an SVG file to a PNG file for compatibility or specific use cases, you can use −
rsvg-convert -f png input.svg -o temp.png
This command converts the input.svg file into a JPEG format, resulting in the file output.jpg.

Converting SVG to PNG
To convert an SVG file to a PNG file, which is useful for web use or applications that require PNG images, you can use the following command −
rsvg-convert input.svg -o output.png
This command converts input.svg to a PNG file named output.png.

Preserving Aspect Ratio
When converting an SVG file and you want to ensure that the aspect ratio of the original SVG is preserved, you can use −
rsvg-convert -a input.svg -o output.png
This command converts input.svg to output.png while maintaining the aspect ratio.

Setting DPI
If you need to set the resolution of the output image for print or high-quality display purposes, you can specify the DPI as follows −
rsvg-convert -d 300 -p 300 input.svg -o output.png
This command sets both the horizontal and vertical DPI to 300, converting input.svg to output.png with high resolution.

Specifying Width and Height
When you need the output image to have specific dimensions, you can specify both the width and height with −
rsvg-convert -w 800 -h 600 input.svg -o output.png
This command sets the width to 800 pixels and the height to 600 pixels, then converts input.svg to output.png.

Conclusion
The rsvg command is a powerful tool for converting SVG files to raster images, making it useful for web development, graphic design, and other applications where image conversion is needed.
By understanding its syntax and options, you can efficiently convert SVG files to various raster formats with the desired resolution and dimensions.