Skip to content

Instantly share code, notes, and snippets.

@andershaig
Created May 2, 2012 22:51
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 andershaig/2581136 to your computer and use it in GitHub Desktop.
Save andershaig/2581136 to your computer and use it in GitHub Desktop.
Image to Canvas with CORS
var img = document.createElement('img');
img.onload = function(e) {
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
var url = canvas.toDataURL(); // Succeeds. Canvas won't be dirty.
};
img.crossOrigin = 'anonymous';
img.src = 'http://other-domain.com/image.jpg';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment