如何使用 ImageMagick 将 SVG 转换为 PNG? [英] How to convert a SVG to a PNG with ImageMagick?

查看:61
本文介绍了如何使用 ImageMagick 将 SVG 转换为 PNG?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个定义大小为 16x16 的 SVG 文件.当我使用 ImageMagick 的转换程序将其转换为 PNG 时,我得到了一个 16x16 像素的 PNG,但它太小了:

转换 test.svg test.png

我需要指定输出 PNG 的像素大小.-size 参数似乎被忽略了,-scale 参数在将 PNG 转换为 PNG 之后对其进行缩放.到目前为止,我使用 -density 参数获得的最佳结果:

convert -density 1200 test.svg test.png

但我并不满意,因为我想以像素为单位指定输出大小,而无需进行数学运算来计算密度值.所以我想做这样的事情:

convert -setTheOutputSizeOfThePng 1024x1024 test.svg test.png

那么我在这里必须使用的魔法参数是什么?

解决方案

在这种情况下,我无法从 ImageMagick 获得好的结果,但 Inkscape 在 Linux 和 Windows 上缩放 SVG 方面做得很好:

>

# Inkscape v1.0+inkscape -w 1024 -h 1024 input.svg -o output.png

# Inkscape 比 v1.0 旧inkscape -z -w 1024 -h 1024 input.svg -e output.png

请注意,您可以省略宽度/高度参数之一,以使另一个参数根据输入图像尺寸自动缩放.

以下是使用此命令将 16x16 SVG 缩放为 200x200 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

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?

解决方案

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:

这篇关于如何使用 ImageMagick 将 SVG 转换为 PNG?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆