Skip to content

Instantly share code, notes, and snippets.

@rgbink
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgbink/c7fa4cd873310dc30de6 to your computer and use it in GitHub Desktop.
Save rgbink/c7fa4cd873310dc30de6 to your computer and use it in GitHub Desktop.
// Include Color Thief Script
// https://github.com/lokesh/color-thief
function colorChange(){
//Be sure to include <img id="coverImage" src="" alt=""/>
var $myImage = $("#coverImage");
var colorThief = new ColorThief();
//Grabs 8 swatch color palette from image and sets quality to 5 (0 =slow, 10=default/fast)
var cp = colorThief.getPalette($myImage[0], 8, 5);
//Sets background to 3rd color in the palette.
$('html').css('background-color', 'rgb('+cp[2][0]+','+cp[2][1]+','+cp[2][2]+')');
}
$(document).ready(function() {
//Make sure image is loaded before running.
colorChange();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment