How to Convert SVG to PNG in Linux

SVG (Scalable Vector Graphics) files are commonly used for logos, icons, and illustrations because they can be resized without losing quality.

However, sometimes you need to convert SVG files to a PNG (Portable Network Graphics) format for better compatibility with websites or applications.

In Linux, there are several ways to do this conversion easily, using both command-line tools and graphical applications.

1. Using Inkscape

Inkscape is a powerful, open-source vector graphics editor that supports the SVG format and can easily be used to convert SVG files to PNG format.

If Inkscape is not installed on your system, you can install it using the following commands based on your Linux distribution:

sudo apt install inkscape         [On Debian, Ubuntu and Mint]
sudo yum install inkscape         [On RHEL/CentOS/Fedora and Rocky/AlmaLinux]
sudo emerge -a sys-apps/inkscape  [On Gentoo Linux]
sudo apk add inkscape             [On Alpine Linux]
sudo pacman -S inkscape           [On Arch Linux]
sudo zypper install inkscape      [On OpenSUSE]    
sudo pkg install inkscape         [On FreeBSD]

Once installed, you can use the following command to convert the SVG file to PNG.

inkscape input.svg --export-type=png --export-filename=output.png --export-dpi=300

2. Using ImageMagick

ImageMagick is a versatile tool that can convert images between different formats, including SVG to PNG from the command line.

If ImageMagick is not installed on your system, you can install it using the following commands based on your Linux distribution:

sudo apt install imagemagick         [On Debian, Ubuntu and Mint]
sudo yum install ImageMagick         [On RHEL/CentOS/Fedora and Rocky/AlmaLinux]
sudo emerge -a sys-apps/imagemagick  [On Gentoo Linux]
sudo apk add imagemagick             [On Alpine Linux]
sudo pacman -S imagemagick           [On Arch Linux]
sudo zypper install imagemagick      [On OpenSUSE]    
sudo pkg install imagemagick         [On FreeBSD]

Once ImageMagick is installed, you can convert SVG files to PNG by running:

convert input.svg output.png

If you want to set a custom resolution for the output PNG file, use the -density option.

convert -density 300 input.svg output.png

3. Using rsvg-convert (Part of librsvg)

rsvg-convert is a command-line tool that is part of the librsvg package, which is lightweight and specifically designed for converting SVG files.

If rsvg-convert: is not installed on your system, you can install it using the following commands based on your Linux distribution:

sudo apt install librsvg2-bin         [On Debian, Ubuntu and Mint]
sudo yum install librsvg2-tools       [On RHEL/CentOS/Fedora and Rocky/AlmaLinux]
sudo emerge -a gnome-base/librsvg     [On Gentoo Linux]
sudo apk add librsvg                  [On Alpine Linux]
sudo pacman -S librsvg                [On Arch Linux]
sudo zypper install librsvg2-tools    [On OpenSUSE]    
sudo pkg install librsvg2             [On FreeBSD]

Once rsvg-convert is installed, you can convert an SVG file to PNG by running the following command:

rsvg-convert -o output.png input.svg

You can specify the width or height of the output image using -w (width) or -h (height):

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

4. Batch Conversion of SVG to PNG

If you have multiple SVG files and want to convert them all to PNG at once, you can use a simple shell loop.

Using Inkscape:

for file in *.svg; do
  inkscape "$file" --export-type=png --export-filename="${file%.svg}.png"
done

Using ImageMagick:

for file in *.svg; do
  convert "$file" "${file%.svg}.png"
done

This loop will convert all .svg files in the current directory to .png.

Conclusion

Converting SVG to PNG in Linux is a simple task that can be done using various tools. Whether you prefer a graphical tool like Inkscape, the flexibility of ImageMagick, or a quick command-line tool like rsvg-convert, Linux provides several easy methods for this conversion.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.