How to convert a SVG to a PNG with ImageMagick?

前端 未结 18 1822
一个人的身影
一个人的身影 2020-11-28 17:04

I have a SVG file that has a defined size of 16x16. When I use ImageMagick\'s convert program to convert it into a PNG, then I get a 16x16 pixel PNG which is way too small:<

相关标签:
18条回答
  • 2020-11-28 17:32

    The top answer by @808sound did not work for me. I wanted to resize

    and got

    So instead I opened up Inkscape, then went to File, Export as PNG fileand a GUI box popped up that allowed me to set the exact dimensions I needed.

    Version on Ubuntu 16.04 Linux: Inkscape 0.91 (September 2016)

    (This image is from Kenney.nl's asset packs by the way)

    0 讨论(0)
  • 2020-11-28 17:33

    I came to this post - but I just wanted to do the conversion by batch and quick without the usage of any parameters (due to several files with different sizes).

    rsvg drawing.svg drawing.png
    

    For me the requirements were probably a bit easier than for the original author. (Wanted to use SVGs in MS PowerPoint, but it doesn't allow)

    0 讨论(0)
  • 2020-11-28 17:33

    Without librsvg, you may get a black png/jpeg image. We have to install librsvg to convert svg file with imagemagick.

    Ubuntu

     sudo apt-get install imagemagick librsvg
     convert -density 1200 test.svg test.png
    
    

    MacOS

     brew install imagemagick librsvg
     convert -density 1200 test.svg test.png
    
    
    0 讨论(0)
  • 2020-11-28 17:33

    On macOS using brew, using librsvg directly works well

    brew install librsvg
    rsvg-convert test.svg -o test.png
    

    Many options are available via rsvg-convert --help

    0 讨论(0)
  • 2020-11-28 17:40

    After following the steps in Jose Alban's answer, I was able to get ImageMagick to work just fine using the following command:

    convert -density 1536 -background none -resize 100x100 input.svg output-100.png
    

    The number 1536 comes from a ballpark estimate of density, see this answer for more information.

    0 讨论(0)
  • 2020-11-28 17:44

    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

    0 讨论(0)
提交回复
热议问题