Canvas is tainted due to CORS | Sololearn: Learn to code for FREE!


Canvas is tainted due to CORS

I am using an image I have downloaded which is in the same folder with the rest of my files, I view the page offline, I'm not using a server, and for some reason I get security error when I try to use getImageData(), how do I fix it?

2/23/2021 9:16:01 AM


2 Answers

New Answer


You must use a server for getImage() function. If you're using vscode, you can download the liveserver extension to work with offline server


Set image crossOrigin property to "Anonymous" to bypass cors. Eg. var img = new Image(); img.crossOrigin = "Anonymous"; // to bypass cors for imgur image link img.src = "";