如何将PNG图像转换为SVG?
当前回答
我刚刚发现这个问题和答案,因为我正试图做同样的事情!我不想使用其他提到的工具。(不想把我的电子邮件给别人,也不想付钱)。我发现Inkscape (v0.91)可以做得很好。本教程简单易懂。
它很简单,选择你的位图在Inkskape和Shift+Alt+B。
其他回答
png是位图图像风格,SVG是支持位图的基于矢量的图形设计,因此它不会将图像转换为矢量,只是将图像嵌入到基于矢量的格式中。你可以使用免费的http://www.inkscape.org/来实现。它会嵌入它,但是它也有一个Live Trace之类的引擎,如果你愿意,它会尝试将它转换为路径(使用potrace)。查看adobe illustrator中的实时跟踪(商业)是一个例子:
http://graphicssoft.about.com/od/illustrator/ss/sflivetrace.htm
I'm assuming that you wish to write software to do this. To do it naively you would just find lines and set the vectors. To do it intelligently, you attempt to fit shapes onto the drawing (model fitting). Additionally, you should attempt to ascertain bitmaped regions (regions you can't model through shames or applying textures. I would not recommend going this route as that it will take quite a bit of time and require a bit of graphics and computer vision knowledge. However, the output will much and scale much better than your original output.
如果你使用的是Linux系统,imagemagick是完美的。即
convert somefile.png somefile.svg
这适用于大量不同的格式。
用于其他媒体,如视频和音频使用(ffmpeg) 我知道你清楚地说明png到svg,然而;这仍然与媒体有关。
ffmpeg -i somefile.mp3 somefile.ogg
如果你想浏览大量的文件,这是一个小技巧;一个循环使用基本的shell技巧。
for f in *.jpg; do convert $f ${f%jpg}png; done
这将删除jpg并添加png,这告诉转换你想要的。
potrace不支持PNG作为输入文件,而是支持PNM。 因此,首先将PNG转换为PNM:
convert file.png file.pnm # PNG to PNM
potrace file.pnm -s -o file.svg # PNM to SVG
解释选项
potrace -s =>输出文件是SVG potrace -o file.svg =>将输出写入file.svg
例子
输入文件= 2017.png
convert 2017.png 2017.pnm
临时文件= 2017.pnm
potrace 2017.pnm -s -o 2017.svg
输出文件= 2017.svg
脚本
ykarikos提出了一个脚本png2svg.sh,我已经改进了:
#!/bin/bash
File_png="${1?:Usage: $0 file.png}"
if [[ ! -s "$File_png" ]]; then
echo >&2 "The first argument ($File_png)"
echo >&2 "must be a file having a size greater than zero"
( set -x ; ls -s "$File_png" )
exit 1
fi
File="${File_png%.*}"
convert "$File_png" "$File.pnm" # PNG to PNM
potrace "$File.pnm" -s -o "$File.svg" # PNM to SVG
rm "$File.pnm" # Remove PNM
一行命令
如果你想转换很多文件,你也可以使用下面的单行命令:
( set -x ; for f_png in *.png ; do f="${f_png%.png}" ; convert "$f_png" "$f.pnm" && potrace "$f.pnm" -s -o "$f.svg" ; done )
另请参阅
也可以在维基百科上看到栅格转换器和矢量转换器的比较。
有一个网站,你可以上传你的图片,并看到结果。
http://vectormagic.com/home
但是如果你想下载你的svg-image,你需要注册。 (注册即可免费获得2张图片)