我有一个包含base64编码(data-uri)的svg图像的文件。该文件以
data:image/svg+xml;base64,PHN....
开头。如何在Linux中将其解码为.svg文件?
data:image
等)复制/粘贴到现代浏览器的URL栏中,它会为你解密。然后你可以将页面简单地保存为SVG格式。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)
.py
扩展名保存,例如aaabbb.py
,然后像这样执行它:python aaabbb.py
base64 --decode < "your base64 data here"
进行操作。而且在传递之前,你可能需要去掉 data:image/svg+xml;base64,
部分。我解决了这个问题:
let url = 'PHN2ZyBpZD0iTGF5ZXJfMM...'
var svg = decodeURIComponent(escape(window.atob(url)));