Skip to content

Instantly share code, notes, and snippets.

@lucnap
Created November 16, 2017 17:37
Show Gist options
  • Save lucnap/98158dd8bd5197f79433b8eab411ab77 to your computer and use it in GitHub Desktop.
Save lucnap/98158dd8bd5197f79433b8eab411ab77 to your computer and use it in GitHub Desktop.
Javascript image to dataurl
var imageToDataURL = function(url, callback) {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
var reader = new FileReader();
reader.onloadend = function() {
callback(reader.result);
}
reader.readAsDataURL(xhr.response);
};
xhr.open('GET', url);
xhr.responseType = 'blob';
xhr.send();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment