ImageMagick: How to Convert SVG to PNG

Updated

Learn how to convert an SVG file to PNG using ImageMagick

ImageMagick: How to Convert SVG to PNG

Before we start, make sure you have ImageMagick installed on your computer and your SVG file ready in a folder. If you don't have it yet, run this command:

brew install imagemagick

First, open your terminal and navigate to the folder that has your file. To convert it, run this command:

magick input.svg output.png

Just remember to replace input.svg with your actual filename. It works, but the PNG comes out small and with a white background. To fix that, add -background none and -size before the input file:

magick -background none -size 1024x1024 input.svg output.png

The -background none option keeps the background transparent, and -size 1024x1024 sets the size in pixels. Always put these options before input.svg, or ImageMagick won't apply them. Don't worry if you don't see a success message, the command finishes quietly.

To make sure everything worked, run open output.png and check the result.

undefined

One more tip: to convert every SVG in the folder at once, use mogrify:

magick mogrify -background none -format png *.svg

If you want a sharper render, add -density 300 before the input file.