Cross-origin data in HTML5 canvas Cross-origin data in HTML5 canvas google-chrome google-chrome

Cross-origin data in HTML5 canvas


To enable CORS (Cross-Origin Resource Sharing) for your images pass the HTTP header with the image response:

Access-Control-Allow-Origin: *

The origin is determined by domain and protocol (e.g. http and https are not the same) of the webpage and not the location of the script.

If you are running locally using file:// this is generally always seen as a cross domain issue; so its better to go via

http://localhost/


To solve the cross domain issue with file://, you can start chrome with the parameter

--allow-file-access-from-files


var img = new Image();img.onload = function() {    canvas.drawImage(img, 0, 0);    originalImageData = canvas.getImageData(0,0,width, height)); //chrome will not fail}img.crossOrigin = 'http://profile.ak.fbcdn.net/crossdomain.xml';//crossdomain xml file, this is facebook exampleimg.src = 'picture.jpeg';

Hope this helps