How to convert a SVG to a PNG with ImageMagick?
Solution 1:
I haven't been able to get good results from ImageMagick in this instance, but Inkscape does a nice job of scaling an SVG on Linux and Windows:
# Inkscape v1.0+
inkscape -w 1024 -h 1024 input.svg -o output.png
# Inkscape older than v1.0
inkscape -z -w 1024 -h 1024 input.svg -e output.png
Note that you can omit one of the width/height parameters to have the other parameter scaled automatically based on the input image dimensions.
Here's the result of scaling a 16x16 SVG to a 200x200 PNG using this command:
Solution 2:
Try svgexport:
svgexport input.svg output.png 64x
svgexport input.svg output.png 1024:1024
svgexport is a simple cross-platform command line tool that I have made for exporting svg files to jpg and png, see here for more options. To install svgexport install npm, then run:
npm install svgexport -g
Edit: If you find an issue with the library, please submit it on GitHub, thanks!
Solution 3:
This is not perfect but it does the job.
convert -density 1200 -resize 200x200 source.svg target.png
Basically it increases the DPI high enough (just use an educated/safe guess) that resizing is done with adequate quality. I was trying to find a proper solution to this but after a while decided this was good enough for my current need.
Note: Use 200x200! to force the given resolution