18

I have a file containing a svg image which is base64 encoded (data-uri). The file starts with

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

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

Ahmed Salman Tahir
  • 1,783
  • 1
  • 17
  • 26
ni_hao
  • 404
  • 2
  • 5
  • 16

7 Answers7

44

You can copy/paste the string (data:image etc. included) in the url bar of a modern browser; it will decrypt it for you. Then you can simply save the page as an svg.

Iazel
  • 2,296
  • 19
  • 23
7

You could use an online base64 decoder, such as http://www.base64decode.org/

Paul LeBeau
  • 97,474
  • 9
  • 154
  • 181
7

To address the OP question:

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

Since linux has python by default, I suggest to use python script.

Here is a working example:

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)

If you are new to python, simply copy-paste the code above into a file with .py extension, for example aaabbb.py and then execute it like this:

python aaabbb.py
Nikita Kurtin
  • 5,889
  • 4
  • 44
  • 48
1

You can use e.g base64 --decode < "your base64 data here". And you probably need to strip off the data:image/svg+xml;base64, part before passing it in.

Erik Dahlström
  • 59,452
  • 12
  • 120
  • 139
0

or you can use the online tool http://www.hosting4free.info/Base64Decode/Base64-Decode.jsp

0

I use SVG online decoder, fast and simple https://base64.online/decoders/decode-base64-to-svg

0

I resolved problem:

let url = 'PHN2ZyBpZD0iTGF5ZXJfMM...'

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

hgiahuyy
  • 180
  • 1
  • 5