如何将PNG图像转换为SVG?
当前回答
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.
其他回答
你可能想看看potrace。
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://www.mobilefish.com/services/image2svg/image2svg.php
用adobe illustrator:
打开Adobe Illustrator。点击“文件”,选择“打开”,将. png文件加载到程序中。在将图像保存为. svg文件之前,根据需要编辑图像。点击“文件”并选择“另存为”。创建新文件名或使用现有名称。确保选择的文件类型是SVG。选择一个目录,点击“保存”保存文件。
or
在线转换器 http://image.online-convert.com/convert-to-svg
我更喜欢人工智能,因为你可以做出任何需要的改变
祝你好运
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.