0

(The whole package can be downloaded from https://drive.google.com/file/d/1vzAYq909e4H7qwZ-opAehmWIHkcjVM1c/view?usp=sharing)

I want to try the OpenSeaDragon demo:

Source code: https://github.com/usnistgov/OpenSeadragonFiltering The same online demo: https://pages.nist.gov/OpenSeadragonFiltering/

to make html and associated js files etc to demo in my local computer.

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 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.

mendel
  • 1
  • 8
  • How are you running locally? Are you just loading files directly from your hard drive or are you running a local server? I think you may need a local server for this. – iangilman Jul 08 '20 at 23:14
  • Hi, I just use browser to open the html files without internet involved. If I open with IE explorer, and allow the blocked content, then the image was shown and filter works well. However, if I open with Chrome browser or other non-IE browser, the image was shown when html was opened, but when I apply any filter, the image was gone and totally black in the canvas. It seems that getImageData command is not allowed locally, so I need to use TCP/IP port to mimic surfing internet to get access to these html file? – mendel Jul 09 '20 at 05:11
  • I'm pretty sure for this scenario you need to have a local server running. I don't know what the easiest way to do that on Windows would be. I believe XAMPP is one good option: https://www.apachefriends.org/ Or you could write a little Node server: https://nodejs.org/ Here's another suggestion (using Python): https://developer.mozilla.org/en-US/docs/Learn/Common_questions/set_up_a_local_testing_server Or maybe just IIS: https://learn.microsoft.com/en-us/previous-versions/ms181052(v=vs.80)?redirectedfrom=MSDN – iangilman Jul 10 '20 at 00:22

0 Answers0