DEV Community

sudo-self
sudo-self

Posted on

1 1 1 1 1

Base 64

Upload an image
base64 encode
download as a .txt
download as a .css (background use)
copy string to clipboard

Buttons

//copy to clipboard

function copyToClipboard() {
  const textarea = document.getElementById("encodedCode");
  textarea.select();
  document.execCommand("copy");
  alert("Code copied to clipboard!");
}

//download txt

function downloadImage() {
  const base64EncodedImage = document.getElementById("encodedCode").value;
  const blob = new Blob([base64EncodedImage], { type: "text/plain" });

  const link = document.createElement("a");
  link.href = URL.createObjectURL(blob);
  link.download = "sudo-self.txt"; //file name here//
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);
  alert("Text file downloaded!");
}

//download css

function downloadCSS() {
  const base64EncodedImage = document.getElementById("encodedCode").value;
  const cssContent = `body {
        background-image: url("${base64EncodedImage}");
        background-repeat: no-repeat;
        background-size: 80%;
        background-attachment: fixed;
      }`;
  const blob = new Blob([cssContent], { type: "text/plain" });
  const link = document.createElement("a");
  link.href = URL.createObjectURL(blob);
  link.download = "sudo-self.css"; //file name here//
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);
  alert("CSS file downloaded!");
}

function displayImage(input) {
  var file = input.files[0];
  var imageType = /image.*/;

  if (file.type.match(imageType)) {
    var reader = new FileReader();

    reader.onload = function (e) {
      var img = new Image();
      img.src = reader.result;

      img.onload = function () {
        var width = this.width;
        var height = this.height;
        document.getElementById("thumbnail").src = this.src;
        document.getElementById("thumbnail").style.display = "inline";
        document.getElementById("resolution").innerText =
          width + " x " + height;
      };
    };

    reader.readAsDataURL(file);
  } else {
    alert("File format not supported!");
  }
}
Enter fullscreen mode Exit fullscreen mode

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Cloudinary image

Video API: manage, encode, and optimize for any device, channel or network condition. Deliver branded video experiences in minutes and get deep engagement insights.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay