I am using this command to generate a sharp 512px wide version of an SVG file that I have:

convert -geometry 256 pinterest.svg pinterest.png

This is the source file:

<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
         width="16px" height="16px" viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
<path fill="#231F20" d="M8,0C3.582,0,0,3.582,0,8c0,3.275,1.97,6.09,4.789,7.327c-0.022-0.559-0.005-1.229,0.139-1.837

However it produces a blurry PNG:


As my source is a vector illustration, I was expecting to get a sharp image. Is there a way to do so?

  • 2
    The problem is the width="16px" height="16px" in the SVG file. Try changing the ImageMagick command to convert -resize 3200% pinterest.svg pinterest.png for a 512x512 image. Not sure if you'll need a -geometry 512 too or not.
    – martineau
    May 23, 2013 at 2:41
  • That didn't work either. I tried it with and without -geometry. It produces a blurry image. Even -density doesn't work. However I managed to achieve my desired results using Apache Batik. May 23, 2013 at 5:55
  • 1
    A slightly different approach might be something like what is described in this answer.
    – martineau
    May 23, 2013 at 7:02

4 Answers 4


I had the same problem, but I sort of went around it by setting the density first.

From command line:

for %f in (*.svg) do (convert -antialias -background transparent -density 600 -resize 1024x1024 %f %~nf.png)
convert -density 2304 pinterest.svg pinterest.png

Because the original DPI is 72 and the pixel size is 16x16, so 512/16*72 is 2304.


I didn't find a way to solve this issue using ImageMagick, but Apache Batik's rasterize script can be used to convert and resize the SVG to PNG in a lossless fashion.

java -jar batik-rasterizer.jar samples/batikFX.svg

See here for more information.

  • 2
    Just a nitpick, but it really doesn't make sense to call a conversion from vector to raster graphics "lossless" -- an image file is a completely different representation and will always be an approximation of the graphics defined in vector format.
    – martineau
    May 23, 2013 at 7:05

Use inkscape instead

Since it does not seem possible to easily determine the -density value without a bit more scripting, as also confirmed at https://stackoverflow.com/questions/9853325/how-to-convert-a-svg-to-a-png-with-imagemagick I recommend just using inkscape instead, which does that for you:

inkscape -w 512 -h 512 -b FFF -e main.png main.svg 


enter image description here

Tested on Inkscape 0.92.5, Ubuntu 20.04.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.