Skip to content

Instantly share code, notes, and snippets.

@d0peCode
Created June 27, 2019 06:25
Show Gist options
  • Save d0peCode/c56bd1a6ebbb7ff08a60ed2a3441eada to your computer and use it in GitHub Desktop.
Save d0peCode/c56bd1a6ebbb7ff08a60ed2a3441eada to your computer and use it in GitHub Desktop.
const getPixels = require("get-pixels");
//1px only black https://i.imgur.com/dStJ1Og.png
//2px only black https://i.imgur.com/5z46WVp.png
//88x62px only black https://i.imgur.com/ZtGMUh9.png
//88x62px black and red https://i.imgur.com/67IZCaD.png
//220x297px black and red https://i.imgur.com/KTNnJGF.jpg
function check(uintArr) {
let r = uintArr[0], g = uintArr[1], b = uintArr[2], a = uintArr[3];
for (let i = 0, l = uintArr.length; i < l; i += 4) {
if (
r !== uintArr[i] ||
g !== uintArr[i+1] ||
b !== uintArr[i+2] ||
a !== uintArr[i+3]
) {
return false;
}
}
return true;
}
getPixels("https://i.imgur.com/JiHtQuR.jpg", function(err, ndarray) {
if(err) {
console.log("Bad image path!");
return;
}
const uintArr = new Uint8Array(ndarray.data);
console.log('Is image one color? ', check(uintArr));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment