Created
June 27, 2019 06:23
-
-
Save d0peCode/95942d20e9fb8d20623f0dfeebb0e55d 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
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 | |
//3000x4000px black with red dot(1px) https://i.imgur.com/JiHtQuR.jpg | |
getPixels("https://i.imgur.com/JiHtQuR.jpg", function(err, ndarray) { | |
if(err) { | |
console.log("Bad image path!"); | |
return; | |
} | |
const firstPixel = [ndarray.data[0], ndarray.data[1], ndarray.data[2], ndarray.data[3]]; | |
const dummyArray = new Uint8Array(Array(ndarray.data.length / 4).fill(firstPixel).flat()); | |
const originalArrString = JSON.stringify(ndarray.data); | |
const dummyArrString = JSON.stringify(dummyArray); | |
if(originalArrString === dummyArrString) { | |
console.log('image is in one color') | |
} else { | |
console.log('image is NOT in one color') | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment