var ctx = document.querySelector('canvas').getContext('2d');
var img = document.querySelector('img');
if (img.complete) drawBackground();
else img.onload = drawBackground;
function drawBackground() {
ctx.drawImage(img, 0, 0);
var d = ctx.getImageData(0, 0, 1, 1).data;
img.parentNode.style.backgroundColor = 'rgb(0, 1, 2)'.replace(/\d/g, function(s) {
return d[s];
});
}