关于linux:将base64 svg数据解码为svg文件

decode base64 svg data to a svg file

我有一个文件,其中包含一个以base64编码的svg图像(data-uri)。该文件以

开头

data:image / svg xml; base64,PHN ....

如何在Linux中将其解码为.svg文件?


您可以在现代浏览器的网址栏中复制/粘贴字符串(包括data:image等);它将为您解密,然后您只需将页面另存为svg。


您可以使用在线base64解码器,例如http://www.base64decode.org/


要解决OP问题:

How to decode this to a .svg file in linux ?

由于linux默认具有python,因此我建议使用python脚本。

这是一个有效的示例:

1
2
3
4
5
6
7
8
9
10
import base64

#change"YOURFILE" with the name of your original file
with open("YOURFILE","rb") as f: encoded = f.read()

encoded = encoded.replace("data:image/svg+xml;base64,","")
decoded = base64.b64decode(encoded)

#change"NEWFILE" with the name that you want to give your new svg
with open("NEWFILE.svg","wb") as f: f.write(decoded)

如果您是python的新手,只需将上面的代码复制粘贴到具有.py扩展名的文件(例如aaabbb.py)中,然后按如下所示执行它:

1
python aaabbb.py

您可以使用例如base64 --decode <"your base64 data here"。而且您可能需要先除去data:image/svg+xml;base64,部分,然后再将其传递。


我使用SVG在线解码器,快速,简单
https://base64.online/decoders/decode-base64-to-svg


或者您可以使用在线工具
http://www.hosting4free.info/Base64Decode/Base64-Decode.jsp