将Base64编码的SVG数据解码为SVG文件

18

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

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

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

7个回答

46
你可以将字符串(包括data:image等)复制/粘贴到现代浏览器的URL栏中,它会为你解密。然后你可以将页面简单地保存为SVG格式。

复制/粘贴到浏览器地址栏,点赞。 - Ibrahim Awad
除了保存之外,我们还可以直接使用浏览器开发者工具进行检查。 - Friedrich -- Слава Україні

7

7
为了回答这个问题:
如何在Linux中将此解码为.svg文件?
由于Linux默认有Python,建议使用Python脚本。
以下是一个可行的示例:
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,然后像这样执行它:
python aaabbb.py

1
你可以使用例如 base64 --decode < "your base64 data here" 进行操作。而且在传递之前,你可能需要去掉 data:image/svg+xml;base64, 部分。

0

0

0

我解决了这个问题:

let url = 'PHN2ZyBpZD0iTGF5ZXJfMM...'

var svg = decodeURIComponent(escape(window.atob(url)));


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接