niklasvh/html2canvas — Issue #45: Use JavaScript 'new Image()' object instead of proxy when available.
Author: gatapia
Created: 2012-01-12 05:15:53+00:00
State: open

Is there a reason why we cannot use something like:
loadImage(url, callback) {
var img = new Image();
img.onload = function() {
var canvas = document.createElement('canvas');
canvas.width = img.width;
canvas.height = img.height;
var ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
callback(canvas.toDataURL('image/png'));
};
img.src = url;
}

This would save the need for a proxy no?

Note: I have not tried this, I don't know the limitations (x-domain, how to handle css backgrounds, etc). So this could be totally stupid, but I thought I'd mention it in case someone knows why this is not a good idea. Save me the effort of trying.

Thanks