How do i get image data from external url - and return colors
<p>Im using clusterfck.js to analyze and return colors. I wan't to grap images from search-results, but it seems to be a problem with the way clusterfck does the data reading. Here's the code from clusterfck:</p>

<pre><code>$(".kmeans-button").click(function() {
   if (!colors) {
      colors = getImageColors();
   }
   var k = $(this).attr("data-k"); // $.data() returned undefined
   $("#clusters").empty().append("&lt;div&gt;calculating distances...&lt;/div&gt;");
   kmeans.clusterColors(colors, k); // Threaded analyzing (worker)
})

function getImageColors() {
    var img = $("#test-image");
    var width = img.width();
    var height = img.height();
    var canvas = document.createElement('canvas');
    canvas.width = width;
    canvas.height = height;

    var context = canvas.getContext("2d");
    context.drawImage(img.get(0), 0, 0);

    var data = context.getImageData(0, 0, width, height).data;
    var colors = [];
    for(var x = 0; x &lt; width-12; x += 3) {
    for(var y = 0; y &lt; height-12; y += 3) { // sample image, every 3rd row and column
    var offs = x*4 + y*4*width;
    var color = [data[offs + 0], data[offs + 1], data[offs + 2]];
    colors.push(color);
    }
  }
return colors;
}
</code></pre>

<p>I tried to put in  img.crossOrigin = "Anonymous"; with no luck. I guess it needs to be loaded in af function and somehow callback colors. This is the best i could come up with, but it's not working.</p>

<pre><code>$(".kmeans-button").click(function() {
   if (!colors) {
        getImageColors2(function(colors2) {
        colors=colors2.slice(0);
        var k = $(this).attr("data-k-e"); // $.data() returned undefined
        $("#clusters").empty().append("&lt;div&gt;calculating colors...&lt;/div&gt;");
        kmeans.clusterColors(colors, k);
    })
}
}) 


function getImageColors2(callback) {
var img2= document.getElementById("test-image");
var img = new Image();  
img.onload = function () {
  var width = img.width();
  var height = img.height();

  var canvas = document.createElement('canvas');
  canvas.width = width;
  canvas.height = height;

  var context = canvas.getContext("2d");
  context.drawImage(img.get(0), 0, 0);

  var data = context.getImageData(0, 0, width, height).data;
  var colors = [];
  for(var x = 0; x &lt; width-12; x += 3) {
    for(var y = 0; y &lt; height-12; y += 3) { // sample image, every 3rd row and column
     var offs = x*4 + y*4*width;
     var color = [data[offs + 0], data[offs + 1], data[offs + 2]];
     colors.push(color);
      }
    }
    callback(colors);
  }
  img.src=img2.src;
}
</code></pre>

<p>I assume that it can't access the data without loading into a image when on a external server. What am i missing her ? Maybe i got it all wrong ?</p>