DEV Community

Jason McNeill
Jason McNeill

Posted on

Answer: How does Twitter extract meaningful subject colors from image pixel data?

Something like the example below might be found helpful for what you want to accomplish.

function getAverageColourAsRGB(img) {
  var canvas = document.createElement('canvas'),
    context = canvas.getContext && canvas.getContext('2d'),
    rgb = {
      r: 102,
      g: 102,
      b: 102
    },
    pixelInterval = 5,
    count = 0,
    i = -4,
    data, length;

Top comments (0)