Last active
August 29, 2015 14:20
-
-
Save rgbink/c7fa4cd873310dc30de6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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