Skip to content

Instantly share code, notes, and snippets.

@dagingaa
Created March 21, 2019 14:34
Show Gist options
  • Save dagingaa/6685c37fe9d9dbc305abf79059049a5c to your computer and use it in GitHub Desktop.
Save dagingaa/6685c37fe9d9dbc305abf79059049a5c to your computer and use it in GitHub Desktop.
src = "url_to_imgur"
img = new Image();
img.crossOrigin = "Anonymous";
img.addEventListener("load", analyze, false);
img.src = src;
function analyze() {
canvas = document.createElement("canvas")
ctx = canvas.getContext("2d")
ctx.drawImage(img, 0, 0, img.width, img.height);
imageData = ctx.getImageData(0,0,img.width, img.height)
value = imageData.data.reduce((cur, i) => cur + i,0)
result = value / imageData.data.length
console.log(result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment