如何将jpeg图像转换为八度的svg? [英] How to convert a jpeg image to an svg in octave?

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

问题描述

我有一个黑色n白色图像,我首先要将其转换为具有透明背景的png,以便仅保留图像的黑色部分.使用此输出图像,我想将其转换为svg.所有这些都通过可连接到服务器后端的代码实现.我该如何实现?

I have a black n white image which i would first like to convert into a png with a transparent background such that only the black part of the image remains. Using this output image i want to convert it to svg. All of this through code which can be connected to a back-end of a server. How can i achieve this?

推荐答案

我不确定这是否总能奏效,但可能会让您入门.我建议 ImageMagick potrace 都是免费的,并且可用于OS X,Linux和Windows.您可以将它们集成到PHP中并作为库函数运行,但是现在,我仅使用终端/命令行.

I am not certain this will always work, but it may get you started. I suggest ImageMagick and potrace both of which are free and available for OS X, Linux and Windows. You can integrate them into PHP and run them as library functions, but for now, I am just using the terminal/Commandline.

让我们开始使用ImageMagick制作棋盘图像

Let's start by making a chessboard image with ImageMagick

convert -size 200x100 pattern:checkerboard chess.jpg

我们现在可以将其设置为纯黑色和白色,如下所示:

We can now threshold that to make it pure black and white, like this:

convert chess.jpg -threshold 50% chessbw.jpg

然后我们要将其发送到 potrace 以制作 svg ,但这需要一个 pbm 格式的文件,因此我们将其转换为 pbm 像这样:

Then we want to send it to potrace to make an svg, but that needs a pbm format file, so we convert it to pbm like this:

convert chess.jpg -threshold 50% chessbw.pbm

现在,我们告诉 potrace 将其转换为 svg

Now we tell potrace to convert that into an svg

potrace -b svg chessbw.pbm -o result.svg

但这不是很容易看到,因此我们得到 ImageMagick result.svg 转换为 JPEG ,但背景为红色这样我们就可以看到透明区域:

but that is not very easy to see, so we get ImageMagick to convert result.svg into a JPEG but with a red background so we can see the transparent areas:

convert -background red result.svg result.jpg

好吧,这不仅仅是一个简单的答案,而是一个解释,因此我将简化为一个可以完成全部工作的命令:

Ok, that was more of an explanation than a simple answer, so I will simplify all that down to one command that does the whole lot:

convert chess.jpg -threshold 50% pbm:- | potrace -b svg - -o result.svg

我希望能帮上忙.

这篇关于如何将jpeg图像转换为八度的svg?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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