在 Javascript 中将 JPEG 转换为 SVG
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4022774/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Conversion of JPEG to SVG in Javascript
提问by Zain
Can anyone help... how to convert Image to Vectors (SVG) through Javascript.......! Any help will be awesome....!
任何人都可以帮助...如何通过Javascript将图像转换为矢量(SVG)......!任何帮助都会很棒......!
回答by arpo
Three options
三个选项
Use Online convert's API
使用在线转换的 API
http://apiv2.online-convert.com/
http://apiv2.online-convert.com/
Run your own node.js server and use Potrace or AutoTrace
运行您自己的 node.js 服务器并使用 Potrace 或 AutoTrace
https://www.npmjs.com/package/potraceused by Online convert https://www.npmjs.com/package/autotrace
https://www.npmjs.com/package/potrace使用在线转换 https://www.npmjs.com/package/autotrace
Or use imagetracerjs client side.
或者使用 imagetracerjs 客户端。
回答by Williham Totland
What you're asking isn't really possible. I mean, you couldtry to do it, but I doubt the results would be particularly satisfying.
你问的根本不可能。我的意思是,您可以尝试这样做,但我怀疑结果是否会特别令人满意。
SVG to JPEG is a one-way conversion; converting a raster image to a vector image is non-trivial, see this question.
SVG 到 JPEG 是一种单向转换;将光栅图像转换为矢量图像并非易事,请参阅此问题。
回答by cancerbero
This project supports both bitmap to SVG and SVG to bitmap (png/jpeg/gif/etc),offers flexible settings, different renderers, JavaScript API for node.js and browser, and Command line .
该项目支持位图转SVG和SVG转位图(png/jpeg/gif/etc),提供灵活的设置,不同的渲染器,node.js和浏览器的JavaScript API,以及命令行。
If configured correctly it generates good results and small svg size. If you just want to transform logos / drawings then no config is needed but if photographs / realistic paintings then some you need to play with the settings until satisfied with size / quality ratio.
如果配置正确,它会产生良好的结果和较小的 svg 大小。如果您只想转换徽标/图纸,则不需要配置,但如果是照片/写实绘画,则需要调整设置,直到对尺寸/质量比感到满意为止。
https://www.npmjs.com/package/svg-png-converter
https://www.npmjs.com/package/svg-png-converter
It has a playground although right now I'm working on a better one since more features has been added:
它有一个游乐场,尽管现在我正在开发一个更好的游乐场,因为添加了更多功能:
https://cancerberosgx.github.io/demos/svg-png-converter/playground/#
https://cancerberosgx.github.io/demos/svg-png-converter/playground/#
回答by serup
I too was looking for a simple conversion from image to svg - however it is not that easy, but I did find a tool which could take simple images (black and white) and transform them into svg files, also result was much nicer, since it somehow smooth the edges out - however when trying with color images, it did not work. If you want to make simple images and then later tranform into svg, then using an online converter could help you
我也在寻找从图像到 svg 的简单转换 - 然而这并不容易,但我确实找到了一个可以拍摄简单图像(黑白)并将它们转换为 svg 文件的工具,结果也更好,因为它以某种方式平滑边缘 - 但是在尝试使用彩色图像时,它不起作用。如果你想制作简单的图像,然后再转换成 svg,那么使用在线转换器可以帮助你
I used this to convert a couple of simple .png images to .svg
我用它来将几个简单的 .png 图像转换为 .svg

