Image-pixel-border

Extract the main colour of an image's borders (jQuery plugin)

View the Project on GitHub madtrax/image-pixel-border

image-pixel-border

A very lightweight and simple jQuery plug-in to extract the main color of an image's border. Just pass a callback as first parameter of the getPixelColor which takes one parameter. The parameter send to your callback will be the hexadecimal color code.

In few words:

  1. Clone the image in a dynamically created HTML canvas element.
  2. Read the pixels of the TOP, BOTTOM, LEFT, RIGHT borders of the image
  3. Extract the most frequent color
  4. Return the extracted color to your callback

Options:

Example :

$('#img1').getPixelColor(function(color) {
    $('body').css('background', color);
});
$('#img1').getPixelColor(function(color) {
    $('.divClass').css('background', color,  5,  3);
});

Live example