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:<
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 file
and 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)
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)
Without librsvg, you may get a black png/jpeg image. We have to install librsvg
to convert
svg file with imagemagick.
sudo apt-get install imagemagick librsvg
convert -density 1200 test.svg test.png
brew install imagemagick librsvg
convert -density 1200 test.svg test.png
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
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.
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