如何使用ImageMagick将SVG转换为PNG? [英] How to convert a SVG to a PNG with ImageMagick?
问题描述
我有一个SVG文件,其定义大小为16x16.当我使用ImageMagick的convert程序将其转换为PNG时,我得到的16x16像素PNG太小了:
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:
convert test.svg test.png
我需要指定输出PNG的像素大小. -size
参数似乎已被忽略,-scale
参数在转换为PNG后的缩放比例.到目前为止,使用-density
参数可获得的最佳结果:
I need to specify the pixel size of the output PNG. -size
parameter seems to be ignored, -scale
parameter scales the PNG after it has been converted to PNG. The best result up to now I got by using the -density
parameter:
convert -density 1200 test.svg test.png
但是我不满意,因为我想以像素为单位指定输出大小,而不用做数学运算来计算密度值.所以我想做这样的事情:
But I'm not satisfied, because I want to specify the output size in pixels without doing math to calculate the density value. So I want to do something like this:
convert -setTheOutputSizeOfThePng 1024x1024 test.svg test.png
那么我在这里必须使用的魔术参数是什么?
So what is the magic parameter I have to use here?
推荐答案
在这种情况下,我无法从ImageMagick获得好的结果,但是Inkscape在Linux和Windows上做得很好:
I haven't been able to get good results from ImageMagick in this instance, but Inkscape does a nice job of it on Linux and Windows:
inkscape -z -w 1024 -h 1024 input.svg -e output.png
编辑(2020年5月):Inkscape 1.0用户,请注意命令行参数已更改:
Edit (May 2020): Inkscape 1.0 users, please note that the command line arguments have changed:
inkscape -w 1024 -h 1024 input.svg --export-filename output.png
这是使用以下命令将16x16 SVG缩放为200x200 PNG的结果:
Here's the result of scaling a 16x16 SVG to a 200x200 PNG using this command:
仅供参考,我的Inkscape版本(在Ubuntu 12.04上)是:
Just for reference, my Inkscape version (on Ubuntu 12.04) is:
Inkscape 0.48.3.1 r9886 (Mar 29 2012)
在Windows 7上为:
and on Windows 7, it is:
Inkscape 0.48.4 r9939 (Dec 17 2012)
这篇关于如何使用ImageMagick将SVG转换为PNG?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!