decode base64 svg data to a svg file - linux

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 ?

You can copy/paste the string (data:imageetc 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.

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

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

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.

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

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

I resolved problem:
let base64 = 'data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMM...'
let url = base64.replace("data:image/svg+xml;base64,", "");
var svg = decodeURIComponent(escape(window.atob(url)));

Related

Convert BASE64 String to PDF file in the IFS on AS400

We receive a BASE64 encoded representation of a courier label PDF in an xml file, which we store in the IFS of our AS400.
We would like to decode this BASE64 string and save it as a .PDF in the IFS so we can then either email it as an attachment or send it to a printer.
I have looked at the capability of the CPYSPLF command using the *PDF WSCST parameter, but this only seems relevant where we would have a Spooled File representation of the label we want to produce.
Does anyone know if this is possible via native iSeries commands/RPG?
One way is to
IFS_READ_UTF8 to load the XML file
XMLPARSE to make it a XML object
XML_TABLE to extract BASE64 data
BASE64_DECODE to decode B64 data to PDF binary stream
IFS_WRITE_BINARY to write that stream as a .pdf file
You could make it a pure sql prodecure, or a SQLRPGLE program.
You also could extract BASE64 date using RPGLE XML-INTO. The use Scott Klement's BASE64 SRVPGM to decode it, then write it to the IFS

encode base64 svg file to path d attribute

I have svg file base64 code, example, data:image/svg+xml;base64,PHN2ZyBpZD0iQ2FwYV8...
I want to convert this svg file using path method, example, <path d="114.939 0H10.449C4.678 .."
There is any converter or trick how can I do that?
Please help.
If someone is wondering I found answer to my own question.
Source link is https://www.sitepoint.com/community/t/converting-an-svg-path-to-a-base64-data-uri-string/278874/7
Easiest solution:
copy base64 string
paste string into browser address bar
browser will generate svg file
check browser source and you will see path d=".." information.

Sanitize Html with base64 image (and convert it to an image)

I have a WebApp with a TinyMCE Html Editor that allows users to input some html from a web page. Images can be pasted and are encoded as base64.
Before saving the user input to DB I use OWASP java-html-sanitizer to discard potential dangerous code (javascript,...).
Some characters in the base64 string of the image are escaped and when I try to get the image back (using apache commons Base64) I'm not able to get a valid image.
Here my code for decoding the image:
byte[] b;
String s = html;
b = s.getBytes(Utility.UTF8);
b = org.apache.commons.codec.binary.Base64.decodeBase64(b);
For the HtmlSanitizer I have done nothing special, just followed the Ebay Policy Example allowing base64 images as suggested here.
Ah, as suggested here I need "to HTML decode before base64 decoding".
I have tried with apache common StringEscapeUtils:
org.apache.commons.lang3.StringEscapeUtils.unescapeHtml4(html);
and it's working. Great.
allowedSchemes: [ 'data'] or allowedSchemesByTag: { img: [ 'data' ]} can be used to allow img tag to accept/allow base64.

Image to binary string

I need this for a scriptUI panel I am working on. I am trying to add a custom image button and the image to be part of the jsx file.
Does somebody know how this kind binary string is achieved, and how do I turn a png file to string of that type '\u0089PNG....' (is it initially Base64 encoded and then another encoding, or is it an encoded Byte array):
http://i.imgur.com/n2wpdmQ.png
Thanks in advance!
I found the solution using ExtendScript Toolkit
var img = File("1.png");
img.open('r');
img.encoding = 'BINARY';
var imgstr = img.read();
img.close();
$.writeln(imgstr.toSource());
It reads the PNG image and outputs the string in the console.
Thanks!

Puzzle. Txt file with encoded text. How to decode?

I have a text file, that contains 50,000 lines of "strange" text:
UEsDBBQAAgAIACaOVEA6e5H83pcBAMLBAQArAAAAW1NhbXN1
bmddIC0gVGVzdCB0YXNrIC0gU291bmQgZGVjcnlwdG9yLnBu
Z+z9ZVBcXdcFiia4B/cgTQPBJTgEC9bBEtwCBCe4uwVtNN24
QyAQ3C24OwR3d3e303zv++T57vl5761zbt06VV3V1bLWXjLX
mGOuNcfe4I8K0phopGgvXrzABMlIKL14AY/x4gUCKQoc7Jsv
3GZA2NtLByVp8RfFQ+Q7sA8IpmLyYi9elEWh339BhH2mMpRR
kn/xwp3uxQvfgBcvbmFf+W6/eOHE/uLFrv6LFwIJL14Q2ab8
/iT04sVTJEhCTMVVdz8VMUW18+6JF1Rfv2fh4uISpoGCAsUN
pWIMRfz169f0L99Rmdw3aDKaMWgoxCFFGT8qD5+8rkZuBp86
FupLdS4PvYcs9GwP5/nfDjfkCm8l1m0ZEeHjG+1gv8T5+0LB
FgX+n77owcX59yO2H/tLMLAK7d9vQqioINkm1HAAqv++cEFf
4f9+AHwnfekGVVrL1vj71Ua4r4QSf4EtgTqChOj/vKi4YYXy
7JSY/17EXkoUkJeiWhvK9L/qAWeP8zHEoYT4/s9LlJ+GCqIy
xKjTSfBPU2QiYDV/TcGX/afijBSc7zKMpgTFq6G+/y2XDauZ
gVshlPafij8OocgAYyvQ1O0kRf9bTglWcwwpfSfuPxW/MUUA
Qvs0Awtq//YiD1bzh4hoA/A/Fce8hXVio7BNVedvL8ZhNf/s
ApVJ/FNxHwmsE/ZqK4zFf3vxFVbz/+fD8yTi1xn2lPDWdMXj
aJBUyKivv6TB6wn+wcb89pRA3VHgoTL3cu4IsuDiw8dbIql2
OAhu3teuKD/s6/tNbwcd215q3qfT1GRBa7+hgaNMJkjDnoY2
98VqH9VtwdOnXV9j8jaMXzY1vfNoFHTaNZWNu/90uycGyDuf
gjDj/7dJuDSlnjd9/BVEjSM2u2OKkdaT6xN7xTue
And at this moment, I don't know how to process this text. Effectively it reads like puzzle text.
What is it?
This is a Base64 encoding of a PNG file called Sound decryptor.png.
Use any Base64 decoder to convert it to a file... Such as this one: http://download.cnet.com/Base64-Encoder-Decoder/3000-10250_4-10555647.html
This is Base64 encoded data.
The particular snippet in your question looks like the beginning of a ZIP-file (begins with the typical PK).
This is a base64-encoded ZIP archive, here's the start of it: PK...T#:{‘...[Samsung] - Test task - Sound decryptor.png.... (contains a PNG image, perhaps something else).
This seems to be a Base64 encoded PNG file. Could you post the entire file so we're able to try to decode it?
This looks like Base64 encoded text. Depending on the programming language you use, you should be able to find a function to decode it for you.
For Python, use base64.b64decode(text). For PHP, use base64_decode($text). Other environment have similar facilities.
Do this to decode the Base64 encoded data:
$ base64 -d original.file
P&T#:{üޗÂÁ+[Samsung] - Test task - Sound decryptor.pngìýeP\]×&¸÷ MÁ%8
(...)
$ base64 -d original.file > decoded.file
$ file decoded.file
decoded.file: Zip archive data
As it turns out to be a ZIP file, it can be unzipped by:
$ unzip decoded.file
Command base64 is in coreutils.

Resources