-1

I'm trying to do color-analysis on images, but Chrome's dang cross-origin sharing policy gets in the way http://jsfiddle.net/mrcactu5/d6Qka/15/

Cross-origin image load denied by Cross-Origin Resource Sharing policy. 

I had asked on StackOverflow and got it fixed in a previous version. http://jsfiddle.net/mrcactu5/d6Qka/6/

var image = new Image();
image.crossOrigin = '';
image.src = 'http://upload.wikimedia.org/wikipedia/commons/0/07/Honeycrisp-Apple.jpg';
image.width=200;

Basically my script downloads links to images from Tumblr and run color-thief.js. Simple enough, right?

imgs = Array(); // stores image links

$.getJSON(url, function(data) { 
    for(var i = 0; i < data.response.length; i++){
        if(data.response[i].photos != undefined){
            //console.log(data.response[i].photos[0].alt_sizes[0].url);
            imgs.push(data.response[i].photos[0].alt_sizes[0].url);
        }

    }
}).success( function(imgs){  analyze(imgs); });
john mangual
  • 7,718
  • 13
  • 56
  • 95
  • Use a proxy, like [Simple PHP Proxy](http://benalman.com/projects/php-simple-proxy/) – Barmar Apr 22 '13 at 20:29
  • It's not at all clear what the problem is here. What exactly is not working? What errors are you getting? – Pointy Apr 22 '13 at 20:29

1 Answers1

1

Don't think you can get around cross-origin errors unless you use document.domain setting. This has been asked here, here, and here.

You can check out a different javascript library that does something similar, demo http://www.maxnov.com/getimagedata/#examples-2

Alternatively, you can run your scripts locally.

Community
  • 1
  • 1
katychuang
  • 1,018
  • 8
  • 18