Created
September 27, 2015 12:13
-
-
Save 45deg/c5516ef88e178ca0e4ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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