How to Convert SVG to PNG in Linux

Here are several methods to convert SVG (Scaled Vector Graphics) files to PNG (Portable Network Graphics) in Linux, using both command-line tools and GUI applications.

Alby Andersen

SVG (Scalable Vector Graphics) files are widely used for logos, icons, and illustrations because they can be resized without any loss of quality. However, for improved compatibility with websites or applications, it is sometimes necessary to convert these files to the PNG (Portable Network Graphics) format.

Linux offers several methods to perform this conversion easily, utilizing both command-line utilities and graphical applications.


1. Using Inkscape (Best for Quality)

Inkscape is a powerful vector graphics editor with a CLI (command-line interface) for batch conversions.

Install Inkscape

# Debian/Ubuntu
sudo apt install inkscape

# Fedora
sudo dnf install inkscape

# Arch
sudo pacman -S inkscape

Convert SVG to PNG

inkscape input.svg -o output.png

Set Custom Resolution (DPI)

inkscape input.svg -d 300 -o output.png  # 300 DPI

Specify Width/Height

inkscape input.svg -w 1024 -h 768 -o output.png

Batch Convert All SVGs in a Directory

for file in *.svg; do inkscape "$file" -o "${file%.svg}.png"; done

2. Using ImageMagick (Quick CLI Tool)

ImageMagick’s convert command supports SVG-to-PNG conversion (requires librsvg for SVG rendering).

Install ImageMagick

# Debian/Ubuntu
sudo apt install imagemagick librsvg2-bin

# Fedora
sudo dnf install ImageMagick librsvg2

# Arch
sudo pacman -S imagemagick

Basic Conversion

convert input.svg output.png

Set Dimensions

convert -resize 800x600 input.svg output.png

Adjust DPI

convert -density 300 input.svg output.png  # 300 DPI

Batch Convert

mogrify -format png *.svg  # Converts all SVGs to PNGs

3. Using rsvg-convert (Lightweight CLI Tool)

Part of librsvg, this tool is fast and ideal for headless servers.

Install librsvg

# Debian/Ubuntu
sudo apt install librsvg2-bin

# Fedora
sudo dnf install librsvg2-tools

# Arch
sudo pacman -S librsvg

Basic Conversion

rsvg-convert input.svg -o output.png

Set Width/Height

rsvg-convert -w 800 -h 600 input.svg -o output.png

Adjust DPI

rsvg-convert -d 300 -p 300 input.svg -o output.png

4. Using CairoSVG (Python-Based)

A Python library for SVG-to-PNG conversion.

Install CairoSVG

pip install cairosvg

Convert SVG to PNG

cairosvg input.svg -o output.png

Set Dimensions

cairosvg input.svg -o output.png -W 800 -H 600

5. GUI Tools

Inkscape (Graphical Interface)

  1. Open the SVG file in Inkscape.
  2. Go to File > Export PNG Image.
  3. Adjust settings (resolution, dimensions) and export.

GIMP

  1. Open the SVG file in GIMP.
  2. Go to File > Export As.
  3. Choose PNG as the format and adjust settings.

Key Notes

  • Quality: Inkscape or rsvg-convert generally produce the best results.
  • Batch Processing: Use for loops with Inkscape or mogrify (ImageMagick).
  • DPI/Resolution: Vector graphics (SVG) scale infinitely, but specify DPI for print-ready PNGs.

Troubleshooting

  • Missing Dependencies: Ensure librsvg is installed for ImageMagick/CairoSVG.
  • Blurry Output: Increase DPI (e.g., -d 300) or dimensions.
  • Transparency: PNG supports transparency by default.
Share This Article