Skip to content

Instantly share code, notes, and snippets.

@45deg
Created September 27, 2015 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 45deg/c5516ef88e178ca0e4ee to your computer and use it in GitHub Desktop.
Save 45deg/c5516ef88e178ca0e4ee to your computer and use it in GitHub Desktop.
(function(){
var img = new Image();
var c = document.createElement('canvas');document.body.appendChild(c);
var ctx = c.getContext("2d");
img.src = document.images[0].src;
img.onload = function(){ c.width = img.width; c.height=img.height;
ctx.drawImage(img, 0, 0);
var data = ctx.getImageData(0, 0, img.width, img.height).data;
var arr = []; var pos = [];console.log(img.width,img.height); var are = [];
for(var i = 0; i < img.width * img.height; i++){
var col = 'c' + [data[4*i+0],data[4*i+1],data[4*i+2],data[4*i+3]].join('');
arr[col] = arr[col] ? arr[col]+1 : 1; pos[col] = [i % img.width, i / img.width | 0];
}
for(a in arr){ if(a != 'c255255255255') are.push([arr[a], pos[a]]); }
var poss = (are.sort()[0][1]); // ここのsortが変なのでWrongが出たら are.sort()[0] を are.sort()[1] にした
var q = '?x=' + poss[0] + '&y=' + poss[1]; location.href=img.src.replace(/\/img/, '').replace(/.png/, q);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment