Skip to content

Instantly share code, notes, and snippets.

@tim-smart
Created March 18, 2010 20:06
Show Gist options
  • Select an option

  • Save tim-smart/336808 to your computer and use it in GitHub Desktop.

Select an option

Save tim-smart/336808 to your computer and use it in GitHub Desktop.
// Get the image
var image = document.getElementById('douglas'),
// Make a canvas
canvas = document.createElement('canvas'),
data;
canvas.height = image.height;
canvas.width = image.width;
// Put image on canvas
canvas.getContext('2d').drawImage(image, 0, 0);
// Get base64 encoded data, and un-convert it
data = canvas.toDataURL();
data = atob(data.slice(data.indexOf(',') + 1));
// data is the binary data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment