The cleanest way to convert an SVG to a PNG from the command line is rsvg-convert, the renderer that ships with GNOME's librsvg:
rsvg-convert -w 512 -h 512 in.svg -o out.pngThat is the whole job for most cases. The one thing that trips everyone up is size: an SVG is scalable and has no inherent pixel dimensions, so you have to tell the converter how big the PNG should be. Leave -w/-h off and you get whatever "natural" size the SVG declares, which is often tiny or wrong. The rest of this page is the detail behind the three tools worth using (rsvg-convert, Inkscape, ImageMagick), when to reach for each, and the blurry-output trap that sends people in circles.
If you searched for
svg2png(the old Node package), that tool is dead. It rendered through PhantomJS, which is unmaintained, so the package no longer keeps up. Use one of the maintained options below. For Node specifically, the modern replacement issharp(which renders SVGs through librsvg under the hood), notsvg2png.
rsvg-convert: the sharpest default
librsvg is a real SVG rendering library, and rsvg-convert is its CLI front end. It produces the cleanest, most spec-accurate rasterization of the three tools here, installs small, and runs fast. It is what I reach for first.
# Render at an explicit pixel size
rsvg-convert -w 512 -h 512 in.svg -o out.png
# Scale proportionally so you do not squash the artwork
rsvg-convert -w 1024 --keep-aspect-ratio in.svg -o out.pngTwo flags do the heavy lifting. -w/--width and -h/--height set the output pixel dimensions. --keep-aspect-ratio scales the image proportionally to fit those bounds, which is not the default (for backward compatibility, rsvg-convert will stretch to exactly -w by -h unless you ask it not to), so pass it whenever you set only one dimension or care about the proportions.
Install it where it is not already present:
# macOS
brew install librsvg
# Debian / Ubuntu
sudo apt install librsvg2-binOutput defaults to stdout if you omit -o, so rsvg-convert in.svg > out.png works too. SVGs are transparent by default and rsvg-convert preserves that transparency in the PNG with no extra flag.
Inkscape: highest fidelity for complex SVGs
When an SVG leans on features a lightweight renderer fumbles (filters, blend modes, complex gradients, embedded fonts, clip paths), Inkscape is the most faithful renderer because it is the same engine that draws the file in the editor. It is heavier to install and slower to start, so it is the tool for "the output does not match the design," not the everyday default.
The modern Inkscape 1.x CLI is different from the old 0.x syntax (the old -e/--export-png flags are gone), so make sure you are on the new form:
# Inkscape 1.x: export type plus an explicit output width
inkscape in.svg --export-type=png -w 512
# Name the output file explicitly
inkscape in.svg --export-type=png --export-filename=out.png -w 512--export-type=png selects the format. -w (short for --export-width) sets the output width in pixels; the height is computed automatically to keep the aspect ratio, and -h/--export-height is there if you need to pin both. With no -w, Inkscape falls back to the document's DPI hint, which is usually not what you want for a sized export. If you pass both --export-filename and --export-type, the filename extension has to match the type.
ImageMagick: convenient, but mind the density
ImageMagick is everywhere, so magick ... in.svg out.png is tempting. It works, but with a catch worth understanding because it is the single most common SVG-to-PNG confusion.
magick -background none -density 384 in.svg out.pngHere is the key fact: ImageMagick does not rasterize the SVG itself if it can avoid it. It delegates to an external renderer, preferring librsvg or Inkscape if either is installed, and only falling back to its weak internal MSVG renderer if neither is present. So in practice you are often using librsvg anyway, just through a second layer.
-density is the part people get wrong. It is the rasterization resolution in DPI, and it must come before the input file to take effect. SVG has no pixels, so ImageMagick renders the vector at the given density and that, not a width flag, is what controls how crisp the result is. The default density is 96 DPI, which is why an unqualified magick in.svg out.png so often comes out blurry or pixelated: it rasterized at a low resolution and any later scaling just enlarged a small bitmap. Bump -density to render at the resolution you actually want (384 DPI is 4x the default), or skip the indirection entirely and use rsvg-convert, which sizes by pixels directly. -background none keeps the PNG transparent; without it, ImageMagick fills the SVG's empty areas with white.
"Not authorized" on SVG: the security policy
If magick in.svg out.png fails with attempt to perform an operation not allowed by the security policy 'SVG', the problem is not your command, it is ImageMagick's policy.xml. SVG (and its internal MSVG/MVG cousins) can pull in external files, so many managed, Docker, and distro-hardened installs ship a policy that blocks the coder outright with a line like:
<policy domain="coder" rights="none" pattern="SVG" />Find the active file with magick -list policy (it prints the path at the top). The clean fix is to install a real SVG renderer, librsvg or Inkscape, which ImageMagick then delegates to instead of touching the unsafe internal path; on most systems that alone clears the error. If you must loosen the policy, change that line to rights="read" rather than removing the policy file, and only on a host where you trust the SVGs you are converting. On a hardened or shared box, the safer move is to skip ImageMagick here and run rsvg-convert directly, which has none of this baggage.
Which one should I use?
rsvg-convertfor almost everything: sharpest output, sizes by pixels, fast, small install.- Inkscape when a complex SVG (filters, blend modes, fonts) does not render correctly anywhere else.
- ImageMagick when it is already installed and the SVG is simple, but remember to set
-densityand-background none, and know it is probably calling librsvg for you anyway. - Node project? Use
sharp, not the deadsvg2png. It renders SVGs through librsvg, same engine asrsvg-convert.
Keep the transparent background
SVGs are transparent by default, and a PNG supports an alpha channel, so the transparency should carry through. With rsvg-convert and Inkscape it does automatically. With ImageMagick you have to ask for it, or it flattens onto white:
# Transparent (correct): SVG empty areas stay transparent in the PNG
magick -background none -density 384 in.svg out.png
# Solid background, if that is what you actually want
magick -background white -density 384 in.svg out.pngFAQ
See also
- Convert an image to WebP from the command line: rasterized formats like JPG and PNG to WebP with cwebp and ImageMagick.
- Convert PSD to PNG from the command line: flatten or extract layers from a Photoshop file with ImageMagick.
- The ffmpeg command cheat sheet: the companion reference for video and media conversion from the CLI.
Sources
Authoritative references this article was fact-checked against.
- rsvg-convert manual (librsvg, official)github.com
- Inkscape man page (official)inkscape.org
- ImageMagick command-line options (official)imagemagick.org
- ImageMagick security policy (policy.xml, official)imagemagick.org
- inkscape(1) man page (Arch, current 1.x CLI)man.archlinux.org





