{% extends 'base.html.twig' %}{% block title %}ToBase64.dev - Encode Text to base64{% endblock %}{% block h1 %}Encode text to base64{% endblock %}{% block body %}<div class="row" style="height: 60%;"><div class="padding col-5"><form method="post" action="" class="form" style="height: 100%"><textarea class="form-control" id="input2" name="input2" placeholder="Type (or paste) here..." spellcheck="false" style="width: 100%;height: 100%;"></textarea></form></div><div class="col-2 d-flex flex-column"><div class="padding row" style="margin-top:auto;margin-bottom:auto;"><button type="button" onclick="tobase64()" class="col-12 btn btn-info"><i class="fas fa-long-arrow-alt-right"></i></button></div></div><div class="padding col-5 d-flex flex-column"><div style="height: 85%"><textarea class="form-control" id="output2" name="output" placeholder="Output will be displayed here..." spellcheck="false" style="width: 100%;height: 100%;"></textarea></div><button id="download" type="button" class="btn btn-info" onclick="copyToClipboard('output2')" style="margin-top:auto;">Copy to clipboard</button></div></div><script type="text/javascript">// Add the following code if you want the name of the file appear on select$(".custom-file-input").on("change", function() {var fileName = $(this).val().split("\\").pop();$(this).siblings(".custom-file-label").addClass("selected").html(fileName);});function copyToClipboard(element) {var copyText = document.getElementById(element);copyText.select();document.execCommand("copy");}function download() {var url = document.getElementById('output3').src.replace(/^data:image\/[^;]+/, 'data:image/png');window.open(url);}function toimage() {var string = document.getElementById('input3').value;var image = "data:image/png;base64," + string;document.getElementById('output3').src = image;document.getElementById('download').disabled = false;}function totext() {var Base64 = {_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode: function(e) {var t = "";var n, r, i, s, o, u, a;var f = 0;e = Base64._utf8_encode(e);while (f < e.length) {n = e.charCodeAt(f++);r = e.charCodeAt(f++);i = e.charCodeAt(f++);s = n >> 2;o = (n & 3) << 4 | r >> 4;u = (r & 15) << 2 | i >> 6;a = i & 63;if (isNaN(r)) { u = a = 64 } else if (isNaN(i)) { a = 64 } t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a)}return t},decode: function(e) {var t = "";var n, r, i;var s, o, u, a;var f = 0;e = e.replace(/\\+\\+[++^A-Za-z0-9+/=]/g, "");while (f < e.length) {s = this._keyStr.indexOf(e.charAt(f++));o = this._keyStr.indexOf(e.charAt(f++));u = this._keyStr.indexOf(e.charAt(f++));a = this._keyStr.indexOf(e.charAt(f++));n = s << 2 | o >> 4;r = (o & 15) << 4 | u >> 2;i = (u & 3) << 6 | a;t = t + String.fromCharCode(n);if (u != 64) { t = t + String.fromCharCode(r) }if (a != 64) { t = t + String.fromCharCode(i) }}t = Base64._utf8_decode(t);return t},_utf8_encode: function(e) {e = e.replace(/\r\n/g, "\n");var t = "";for (var n = 0; n < e.length; n++) {var r = e.charCodeAt(n);if (r < 128) { t += String.fromCharCode(r) } else if (r > 127 && r < 2048) {t += String.fromCharCode(r >> 6 | 192);t += String.fromCharCode(r & 63 | 128)} else {t += String.fromCharCode(r >> 12 | 224);t += String.fromCharCode(r >> 6 & 63 | 128);t += String.fromCharCode(r & 63 | 128)}}return t},_utf8_decode: function(e) {var t = "";var n = 0;var r = c1 = c2 = 0;while (n < e.length) {r = e.charCodeAt(n);if (r < 128) {t += String.fromCharCode(r);n++} else if (r > 191 && r < 224) {c2 = e.charCodeAt(n + 1);t += String.fromCharCode((r & 31) << 6 | c2 & 63);n += 2} else {c2 = e.charCodeAt(n + 1);c3 = e.charCodeAt(n + 2);t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63);n += 3}}return t}}// Define the stringvar string = document.getElementById('input4').value;// Encode the Stringvar decodedString = Base64.decode(string);document.getElementById('output4').value = decodedString;}function tobase64() {var Base64 = {_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode: function(e) {var t = "";var n, r, i, s, o, u, a;var f = 0;e = Base64._utf8_encode(e);while (f < e.length) {n = e.charCodeAt(f++);r = e.charCodeAt(f++);i = e.charCodeAt(f++);s = n >> 2;o = (n & 3) << 4 | r >> 4;u = (r & 15) << 2 | i >> 6;a = i & 63;if (isNaN(r)) { u = a = 64 } else if (isNaN(i)) { a = 64 } t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a)}return t},decode: function(e) {var t = "";var n, r, i;var s, o, u, a;var f = 0;e = e.replace(/\\+\\+[++^A-Za-z0-9+/=]/g, "");while (f < e.length) {s = this._keyStr.indexOf(e.charAt(f++));o = this._keyStr.indexOf(e.charAt(f++));u = this._keyStr.indexOf(e.charAt(f++));a = this._keyStr.indexOf(e.charAt(f++));n = s << 2 | o >> 4;r = (o & 15) << 4 | u >> 2;i = (u & 3) << 6 | a;t = t + String.fromCharCode(n);if (u != 64) { t = t + String.fromCharCode(r) }if (a != 64) { t = t + String.fromCharCode(i) }}t = Base64._utf8_decode(t);return t},_utf8_encode: function(e) {e = e.replace(/\r\n/g, "\n");var t = "";for (var n = 0; n < e.length; n++) {var r = e.charCodeAt(n);if (r < 128) { t += String.fromCharCode(r) } else if (r > 127 && r < 2048) {t += String.fromCharCode(r >> 6 | 192);t += String.fromCharCode(r & 63 | 128)} else {t += String.fromCharCode(r >> 12 | 224);t += String.fromCharCode(r >> 6 & 63 | 128);t += String.fromCharCode(r & 63 | 128)}}return t},_utf8_decode: function(e) {var t = "";var n = 0;var r = c1 = c2 = 0;while (n < e.length) {r = e.charCodeAt(n);if (r < 128) {t += String.fromCharCode(r);n++} else if (r > 191 && r < 224) {c2 = e.charCodeAt(n + 1);t += String.fromCharCode((r & 31) << 6 | c2 & 63);n += 2} else {c2 = e.charCodeAt(n + 1);c3 = e.charCodeAt(n + 2);t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63);n += 3}}return t}}// Define the stringvar string = document.getElementById('input2').value;// Encode the Stringvar encodedString = Base64.encode(string);document.getElementById('output2').value = encodedString;}</script><script>function handleFileSelect(evt) {document.getElementById("loading").style.display = "";var files = evt.target.files; // FileList object// Loop through the FileList and render image files as thumbnails.for (var i = 0, f; f = files[i]; i++) {// Only process image files.if (!f.type.match('image.*')) {continue;}var reader = new FileReader();// Closure to capture the file information.reader.onload = (function(theFile) {return function(e) {// Render thumbnail.document.getElementById('imageb64').src = e.target.result;document.getElementById("output3").value = "url('" + e.target.result + "')";document.getElementById("output2").value = e.target.result;document.getElementById("output1").value = e.target.result.split(',')[1];imageB64 = e.target.result;document.getElementById("loading").style.display = "none";};})(f);// Read in the image file as a data URL.reader.readAsDataURL(f);}}//document.getElementById('files').addEventListener('change', handleFileSelect, false);</script>{% endblock %}