黑白PNG到SVG

编程入门 行业动态 更新时间:2024-10-28 06:31:27
本文介绍了黑白PNG到SVG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个河流/陆地面具来区分土地与河流/湖泊。这个文件的大小是(W)4400x(H)21600。

当RAM随即填满时,文件无法打开。我已经将文件分割成3600 * 3600块,并且打开状态良好。然而,我试图在谷歌地图上绘制文件,但系统在叠加图像时仍然变慢。

我想知道是否有办法将3600 * 3600 PNG图像传输到SVG,但仅为黑色和白色之间的边界创建矢量。这在理论上会减小文件的大小。

我目前正在尝试制作SVG文件,但文件大小大致为1GB。它不会在linux(eog)中加载该文件,并且它不会在加载Google地图时加载。

任何帮助都将被赞赏:)

解决方案根据你的图片,你可以用 potrace 和 ImageMagick的。假设您的初始图像是 PNG 这样的文件:

您可以使用 ImageMagick 将其制作为 PBM 格式的图片,例如 potrace 优先选择,然后将其制作为 SVG 像这样:

convert river.png pbm: - | potrace - -s -o river.svg

SVG 文件大约是 PNG 的一半大小。如果有人喜欢看 SVG 文件,它看起来像这样:

<?xml version =1.0standalone =no?> <!DOCTYPE svg PUBLIC - // W3C // DTD SVG 20010904 // ENwww.w3/TR/2001/REC-SVG-20010904/DTD /svg10.dtd\"> < svg version =1.0xmlns =www.w3/2000/svg width =3000.000000ptheight =2000.000000ptviewBox =0 0 3000.000000 2000.000000 preserveAspectRatio =xMidYMid meet> <元数据> 由Peter Selinger 2001-2013编写的potrace 1.11创建< / metadata> < g transform =translate(0.000000,2000.000000)scale(0.100000,-0.100000) fill =#000000stroke =none> <路径d =M4554 16821 c-3 -3 -114 -6 -247 -7 -395 -4 -437 -5 -467 -14 -17 -5 -32 -5 - 34 -1 -5 8 -136 8 -151 -1 -5 -3 -53 -6 -106 -6 -53 0 -113 -5 -135 -11 -21 -5 -76 -11 -121 -13 -46 -1 -83 -5 -83 -8 0 -8 -3 -8 -107 -14 -45 -3 -102 -10 -125 -17 -24 -7 -72 -13 - 108 -15 -71 -3 -90 -7 -134 -23 -16 -7 -31 -9 -34 -6 -3 2 -11 0 -19 -6 -10 -9 -13 -8 - 13 0 0 7 -4 10 -9 6 -5 -3 -31 -8 ... ... -63 -3 -164 -1 -197 4 -18 3 -35 2 -38 -3 -4 -7 -62 -6 -178 3 -21 1 -41 -1 -43 -5 -2 -3 -39 -4 -82 -1 -129 8 -152 8 -152 1 0 -4 -21 -5 -47 -3 -91 8 -135 10 -139 6z/> < / g> < / svg>

I have a river/land mask to differentiate land with rivers/lakes. The size of this file is (W)43,200x(H)21,600.

The file is impossible to open as the RAM fills up instantly. I have split the file into 3600*3600 blocks and they open fine. However I'm trying to plot the file over land in google maps, the system still slows down when overlaying the image.

I'm wondering if there is a way to transfer the 3600*3600 PNG image to SVG, but only create vectors for the boundaries between the black and white colours. This in theory would decrease the size of the file.

I'm currently trying to make an SVG file, but the file size is roughly 1GB in size. It doesn't load the file in linux (eog), and it doesnt load while overlaying over Google maps.

Any help would be appreciated :)

解决方案

Depending on your images, you may be able to do this with potrace and ImageMagick. Let's say your initial image is a PNG file like this:

You can use ImageMagick to make that into a PBM format image, like potrace prefers, and then make that into an SVG like this:

convert river.png pbm:- | potrace - -s -o river.svg

The SVG file is around half the size of the PNG. If anyone likes looking inside SVG files, it looks like this:

<?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "www.w3/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> <svg version="1.0" xmlns="www.w3/2000/svg" width="3000.000000pt" height="2000.000000pt" viewBox="0 0 3000.000000 2000.000000" preserveAspectRatio="xMidYMid meet"> <metadata> Created by potrace 1.11, written by Peter Selinger 2001-2013 </metadata> <g transform="translate(0.000000,2000.000000) scale(0.100000,-0.100000)" fill="#000000" stroke="none"> <path d="M4554 16821 c-3 -3 -114 -6 -247 -7 -395 -4 -437 -5 -467 -14 -17 -5 -32 -5 -34 -1 -5 8 -136 8 -151 -1 -5 -3 -53 -6 -106 -6 -53 0 -113 -5 -135 -11 -21 -5 -76 -11 -121 -13 -46 -1 -83 -5 -83 -8 0 -8 -3 -8 -107 -14 -45 -3 -102 -10 -125 -17 -24 -7 -72 -13 -108 -15 -71 -3 -90 -7 -134 -23 -16 -7 -31 -9 -34 -6 -3 2 -11 0 -19 -6 -10 -9 -13 -8 -13 0 0 7 -4 10 -9 6 -5 -3 -31 -8 ... ... -63 -3 -164 -1 -197 4 -18 3 -35 2 -38 -3 -4 -7 -62 -6 -178 3 -21 1 -41 -1 -43 -5 -2 -3 -39 -4 -82 -1 -129 8 -152 8 -152 1 0 -4 -21 -5 -47 -3 -91 8 -135 10 -139 6z"/> </g> </svg>

更多推荐

黑白PNG到SVG

本文发布于:2023-07-26 18:19:42,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:黑白   PNG   SVG

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!