lokesh / color-thief

Grab the color palette from an image using just Javascript. Works in the browser and in Node.
https://lokeshdhakar.com/projects/color-thief/
MIT License
12.67k stars 1.31k forks source link

CORS error on already loaded image #194

Closed chisholmd closed 4 years ago

chisholmd commented 4 years ago

I have an img object that has already loaded

eg let img = new Image(); img.addEventListener('load', e => resolve(img)); img.addEventListener('error', e => reject(err)); img.src = url;

In my resolve function I am calling color thief const colorThief = new ColorThief(); console.log(colorThief.getColor(img));

Receive error DOMException: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data.

I was assuming that the image is already loaded because I can analyze its height and width etc. But perhaps CORS doesn't kick in until it actually added to the DOM?

Is there a way to extract color info from an img that is not yet added to the DOM?

chisholmd commented 4 years ago

Never mind found your note in the readme