Skip to content

Instantly share code, notes, and snippets.

Embed
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);
})(document.images[0]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.