Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crossOriginPolicy: 'Anonymous' make the demo image unvisible #22

Open
rmd13 opened this issue Jul 3, 2020 · 0 comments
Open

crossOriginPolicy: 'Anonymous' make the demo image unvisible #22

rmd13 opened this issue Jul 3, 2020 · 0 comments

Comments

@rmd13
Copy link

rmd13 commented Jul 3, 2020

Hi
To try the demo on local computer, I download openseadragon and this demo, and highsmith tile image folders, and all the js files needed from the demo website. Then I replace the code in index.html by the dynamic code in the browser for the demo website.
Then I change all the http path in js and html to local file, and specify the viewer object in demo,js and demo-bundle.js as below:

var viewer = new OpenSeadragon({
    id: 'openseadragon',
    prefixUrl: './images/',
    //crossOriginPolicy: 'Anonymous' 
    tileSources: {
        Image: {
            xmlns: 'http://schemas.microsoft.com/deepzoom/2008',
            Url: './highsmith_files/',
            Overlap: '2',
            TileSize: '256',
            Format: 'jpg',
            Size: {
                Height: '9221',
                Width: '7026'
            }
        }
    }
});

If I remove/comment the line:
crossOriginPolicy: 'Anonymous'
then I open index.html and could see exactly the loaded image and filter options. But once I click an filter, although the filter was added to the lower part, but the image turns black forever. The console explorer said:

Uncaught DOMException: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data.
    at Object.tileDrawingHandler [as handler] (file:///D:/QMDownload/9/test3/OpenseadragonDemo/_plugins/demo-bundle.js:45407:57)
    at file:///D:/QMDownload/9/test3/OpenseadragonDemo/_plugins/demo-bundle.js:28662:34
    at $.Viewer.raiseEvent (file:///D:/QMDownload/9/test3/OpenseadragonDemo/_plugins/demo-bundle.js:28684:14)
    at _drawingHandler (file:///D:/QMDownload/9/test3/OpenseadragonDemo/_plugins/demo-bundle.js:43338:23)
    at $.Tile.drawCanvas (file:///D:/QMDownload/9/test3/OpenseadragonDemo/_plugins/demo-bundle.js:40996:10)
    at $.Drawer.drawTile (file:///D:/QMDownload/9/test3/OpenseadragonDemo/_plugins/demo-bundle.js:41659:23)
    at drawTiles (file:///D:/QMDownload/9/test3/OpenseadragonDemo/_plugins/demo-bundle.js:44495:29)
    at updateViewport (file:///D:/QMDownload/9/test3/OpenseadragonDemo/_plugins/demo-bundle.js:43944:6)
    at $.TiledImage.draw (file:///D:/QMDownload/9/test3/OpenseadragonDemo/_plugins/demo-bundle.js:43390:10)
    at $.World.draw (file:///D:/QMDownload/9/test3/OpenseadragonDemo/_plugins/demo-bundle.js:45070:29)

I googled and find an answer that
https://stackoverflow.com/questions/22097747/how-to-fix-getimagedata-error-the-canvas-has-been-tainted-by-cross-origin-data

As others have said you are "tainting" the canvas by loading from a cross origins domain.

https://developer.mozilla.org/en-US/docs/HTML/CORS_Enabled_Image

However, you may be able to prevent this by simply setting:

img.crossOrigin = "Anonymous";
This only works if the remote server sets the following header appropriately:

Access-Control-Allow-Origin "*"
The Dropbox file chooser when using the "direct link" option is a great example of this. I use it on oddprints.com to hoover up images from the remote dropbox image url, into my canvas, and then submit the image data back into my server. All in javascript

So I bring back the
crossOriginPolicy: 'Anonymous' in demo,js and demo-bundle.js, but found that when I open index.html, the image was total black.

How can I solve the problem and make the filter work in local computer ?
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant