stereo-img icon indicating copy to clipboard operation
stereo-img copied to clipboard

Support images from arbitrary origins

Open smketterer opened this issue 3 years ago • 2 comments

Hello, firstly, thank you for your work on this project! I found this project somewhat randomly, searching on Github, so please bear with me.

I'm running into an issue when I started serving my images through S3, that hopefully has an easy fix.

Uncaught (in promise) DOMException: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data.
    at parseStereo (https://cdn.skypack.dev/-/[email protected]/dist=es2019,mode=imports/optimized/stereo-img.js:84:128)
    at async HTMLElement.parse (https://cdn.skypack.dev/-/[email protected]/dist=es2019,mode=imports/optimized/stereo-img.js:220:25)
    at async HTMLElement.parseImageAndInitialize3DScene (https://cdn.skypack.dev/-/[email protected]/dist=es2019,mode=imports/optimized/stereo-img.js:275:5)
    at async HTMLElement.init (https://cdn.skypack.dev/-/[email protected]/dist=es2019,mode=imports/optimized/stereo-img.js:292:5)

I poked around a little bit, and apparently you can set an option to allow anonymous cross-origin on the canvas image: https://stackoverflow.com/questions/22097747/how-to-fix-getimagedata-error-the-canvas-has-been-tainted-by-cross-origin-data

Setting the headers as outlined in the answer there is easy to do on my end.

Perhaps there are alternative solutions as well?

Thanks for taking a look.

smketterer avatar Jan 11 '22 22:01 smketterer

Thanks for reporting. I hadn't try to load an image from a different domain. It's be great to support that since that something regular support.

I will take a closer look, but it seems the server needs to allow CORS and the code might need to be updated with image.crossOrigin = 'anonymous';

steren avatar Jan 12 '22 07:01 steren

I reverted the change because it introduced an issue I see https://github.com/steren/stereo-img/issues/15

steren avatar Jan 31 '22 00:01 steren