Skip to content

Instantly share code, notes, and snippets.

@cfleschhut
Created June 24, 2011 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfleschhut/1043953 to your computer and use it in GitHub Desktop.
Save cfleschhut/1043953 to your computer and use it in GitHub Desktop.
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