The task is not that difficult as it might seem to be. Even you can implement it by yourself. For that you should use the <canvas>
element (it has a possibility to pick up a pixel data).
First, you can take the screenshot of HTML content and transfer it to the <canvas>
. In order to do that, you may use html2canvas library.
Then, you should use the <canvas>
data to pick up the color. Here is the short solution for that:
var img = new Image(),
cbox = $("div"),
canvas = $("canvas"),
context = canvas.get(0).getContext("2d");
img.src = "/img/logo.png";
context.drawImage(img, 0, 0);
canvas.on("mousemove", function(e) {
var data = context.getImageData(e.offsetX, e.offsetY, 1, 1).data,
arr = $.makeArray(data);
cbox.css("background-color", "rgba(" + arr.join(",") + ")");
});
DEMO: http://jsfiddle.net/Fd3pZ/
However, you should consider that the provided solution will work only in browsers which support <canvas>
and rgba()
as CSS color mode (rgb()
can be used instead though).
And here is the complete solution after embedding html2canvas library.
$("body").on("mousemove", "canvas", function(e) {
var data = this.getContext("2d").getImageData(e.offsetX, e.offsetY, 1, 1).data,
arr = $.makeArray(data);
$("#color").css("background-color", "rgba(" + arr.join(",") + ")");
});
$("#content").html2canvas();
DEMO: http://jsfiddle.net/Fd3pZ/1/