使用 ImageMagick 将 SVG 转换为具有抗锯齿功能的透明 PNG [英] Convert SVG to transparent PNG with antialiasing, using ImageMagick
问题描述
我想将 SVG 图像转换为具有透明背景和抗锯齿边缘的 PNG 文件(使用半透明像素).不幸的是,我无法让 ImageMagick 进行抗锯齿处理,边缘看起来总是很糟糕.这是我尝试过的:
I want to convert SVG images to PNG files with transparent background and anti-aliased edges (using semi-transparent pixels). Unfortunately I can't get ImageMagick to do the anti-aliasing, the edges always look terrible. Here's what I tried:
convert +antialias -background transparent in.svg -resize 25x25 out.png
我可以使用任何想法或其他命令行工具吗?
Any ideas or a different command line tool I could use?
推荐答案
Inkscape 会这样做:
Inkscape will do this:
inkscape
--export-png=out.png --export-dpi=200
--export-background-opacity=0 --without-gui in.svg
更新
术语有更改:所有导出参数都抑制了gui,并且输出参数现在仅基于文件类型.例如,png
类型将导致 /path/to/picture.svg
中的文件导出为 /path/to/picture.png
(注意:这会覆盖输出).
Update
The terminology has changed: all the export params suppress gui, and the output parameter is now simply based on the file type. For example, a type of png
will cause a file in /path/to/picture.svg
to be exported as /path/to/picture.png
(caution: this overwrites output).
inkscape
--export-type=png --export-dpi=200
--export-background-opacity=0 picture.svg
注意引用的 wiki 在 --export-type=png
上有引号,这是不正确的.
Note cited wiki has quotes on --export-type=png
, which is incorrect.
如果没有 Inkscape 命令行,MacOS 也可以直接通过 bash 访问:
Also if don't have Inkscape command line, MacOS can access via bash directly:
/Applications/Inkscape.app/Contents/MacOS/inkscape
这篇关于使用 ImageMagick 将 SVG 转换为具有抗锯齿功能的透明 PNG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!