Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Quick base64 image encoding
// adjust image selector in fn-call
// and run this from the (firebug, etc.) console
(function(imgObj) {
var imgsrc = imgObj.src;
var canvas = document.createElement("canvas"),
ctx = canvas.getContext("2d");
canvas.width = imgObj.width;
canvas.height = imgObj.height;
var newimg = new Image();
newimg.src = imgsrc;
newimg.addEventListener("load", function() {
ctx.drawImage(newimg, 0, 0);
window.location = canvas.toDataURL();
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment