templates/base64-to-text.html.twig line 1

Open in your IDE?
  1. {% extends 'base.html.twig' %}
  2. {% block title %}
  3. ToBase64.dev - Decode base64 text and get unencoded text
  4. {% endblock %}
  5. {% block h1 %}Decode base64 to text{% endblock %}
  6. {% block body %}
  7. <div class="row" style="height: 60%;">
  8. <div class="padding col-5">
  9. <form method="post" action="" class="form" style="height: 100%">
  10. <textarea class="form-control" id="input4" name="input3" placeholder="Type (or paste) here..." spellcheck="false" style="width: 100%;height: 100%;"></textarea>
  11. </form>
  12. </div>
  13. <div class="col-2 d-flex flex-column">
  14. <div class="padding row" style="margin-top:auto;margin-bottom:auto;">
  15. <button type="button" onclick="totext()" class="col-12 btn btn-info"><i class="fas fa-long-arrow-alt-right"></i></button>
  16. </div>
  17. </div>
  18. <div class="padding col-5 d-flex flex-column">
  19. <div style="height: 85%">
  20. <textarea class="form-control" id="output4" name="output" placeholder="Output will be displayed here..." spellcheck="false" style="width: 100%;height: 100%;"></textarea>
  21. </div>
  22. <button id="download" type="button" class="btn btn-info" onclick="copyToClipboard('output4')" style="margin-top:auto;">Copy to clipboard!</button>
  23. </div>
  24. </div>
  25. <script type="text/javascript">
  26. // Add the following code if you want the name of the file appear on select
  27. $(".custom-file-input").on("change", function() {
  28. var fileName = $(this).val().split("\\").pop();
  29. $(this).siblings(".custom-file-label").addClass("selected").html(fileName);
  30. });
  31. function copyToClipboard(element) {
  32. var copyText = document.getElementById(element);
  33. copyText.select();
  34. document.execCommand("copy");
  35. }
  36. function download() {
  37. var url = document.getElementById('output3').src.replace(/^data:image\/[^;]+/, 'data:image/png');
  38. var link = document.createElement('a');
  39. link.href = url;
  40. link.download = 'image.png';
  41. document.body.appendChild(link);
  42. link.click();
  43. document.body.removeChild(link);
  44. //window.open(url);
  45. }
  46. function toimage() {
  47. var string = document.getElementById('input3').value;
  48. var image = "data:image/png;base64," + string;
  49. document.getElementById('output3').src = image;
  50. document.getElementById('download').disabled = false;
  51. }
  52. function totext() {
  53. var Base64 = { _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", encode: function(e) { var t = ""; var n, r, i, s, o, u, a; var f = 0;
  54. e = Base64._utf8_encode(e); while (f < e.length) { n = e.charCodeAt(f++);
  55. r = e.charCodeAt(f++);
  56. i = e.charCodeAt(f++);
  57. s = n >> 2;
  58. o = (n & 3) << 4 | r >> 4;
  59. u = (r & 15) << 2 | i >> 6;
  60. 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;
  61. e = e.replace(/\\+\\+[++^A-Za-z0-9+/=]/g, ""); while (f < e.length) { s = this._keyStr.indexOf(e.charAt(f++));
  62. o = this._keyStr.indexOf(e.charAt(f++));
  63. u = this._keyStr.indexOf(e.charAt(f++));
  64. a = this._keyStr.indexOf(e.charAt(f++));
  65. n = s << 2 | o >> 4;
  66. r = (o & 15) << 4 | u >> 2;
  67. i = (u & 3) << 6 | a;
  68. 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);
  69. t += String.fromCharCode(r & 63 | 128) } else { t += String.fromCharCode(r >> 12 | 224);
  70. t += String.fromCharCode(r >> 6 & 63 | 128);
  71. 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);
  72. n++ } else if (r > 191 && r < 224) { c2 = e.charCodeAt(n + 1);
  73. t += String.fromCharCode((r & 31) << 6 | c2 & 63);
  74. n += 2 } else { c2 = e.charCodeAt(n + 1);
  75. c3 = e.charCodeAt(n + 2);
  76. t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
  77. n += 3 } } return t } }
  78. // Define the string
  79. var string = document.getElementById('input4').value;
  80. // Encode the String
  81. var decodedString = Base64.decode(string);
  82. document.getElementById('output4').value = decodedString;
  83. }
  84. function tobase64() {
  85. var Base64 = { _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", encode: function(e) { var t = ""; var n, r, i, s, o, u, a; var f = 0;
  86. e = Base64._utf8_encode(e); while (f < e.length) { n = e.charCodeAt(f++);
  87. r = e.charCodeAt(f++);
  88. i = e.charCodeAt(f++);
  89. s = n >> 2;
  90. o = (n & 3) << 4 | r >> 4;
  91. u = (r & 15) << 2 | i >> 6;
  92. 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;
  93. e = e.replace(/\\+\\+[++^A-Za-z0-9+/=]/g, ""); while (f < e.length) { s = this._keyStr.indexOf(e.charAt(f++));
  94. o = this._keyStr.indexOf(e.charAt(f++));
  95. u = this._keyStr.indexOf(e.charAt(f++));
  96. a = this._keyStr.indexOf(e.charAt(f++));
  97. n = s << 2 | o >> 4;
  98. r = (o & 15) << 4 | u >> 2;
  99. i = (u & 3) << 6 | a;
  100. 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);
  101. t += String.fromCharCode(r & 63 | 128) } else { t += String.fromCharCode(r >> 12 | 224);
  102. t += String.fromCharCode(r >> 6 & 63 | 128);
  103. 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);
  104. n++ } else if (r > 191 && r < 224) { c2 = e.charCodeAt(n + 1);
  105. t += String.fromCharCode((r & 31) << 6 | c2 & 63);
  106. n += 2 } else { c2 = e.charCodeAt(n + 1);
  107. c3 = e.charCodeAt(n + 2);
  108. t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
  109. n += 3 } } return t } }
  110. // Define the string
  111. var string = document.getElementById('input2').value;
  112. // Encode the String
  113. var encodedString = Base64.encode(string);
  114. document.getElementById('output2').value = encodedString;
  115. }
  116. </script>
  117. <style>
  118. </style>
  119. <script>
  120. function handleFileSelect(evt) {
  121. document.getElementById("loading").style.display = "";
  122. var files = evt.target.files; // FileList object
  123. // Loop through the FileList and render image files as thumbnails.
  124. for (var i = 0, f; f = files[i]; i++) {
  125. // Only process image files.
  126. if (!f.type.match('image.*')) {
  127. continue;
  128. }
  129. var reader = new FileReader();
  130. // Closure to capture the file information.
  131. reader.onload = (function(theFile) {
  132. return function(e) {
  133. // Render thumbnail.
  134. document.getElementById('imageb64').src = e.target.result;
  135. document.getElementById("output3").value = "url('" + e.target.result + "')";
  136. document.getElementById("output2").value = e.target.result;
  137. document.getElementById("output1").value = e.target.result.split(',')[1];
  138. imageB64 = e.target.result;
  139. document.getElementById("loading").style.display = "none";
  140. };
  141. })(f);
  142. // Read in the image file as a data URL.
  143. reader.readAsDataURL(f);
  144. }
  145. }
  146. //document.getElementById('files').addEventListener('change', handleFileSelect, false);
  147. </script>
  148. {% endblock %}