Skip to content

Instantly share code, notes, and snippets.

@jennschiffer
Last active August 29, 2015 13:58
Show Gist options
  • Save jennschiffer/10024708 to your computer and use it in GitHub Desktop.
Save jennschiffer/10024708 to your computer and use it in GitHub Desktop.
hex to rgb
var hexToRGB = function(hex) {
var rgbOutput = [];
// check for # or not
if ( hex.substr(0,1) == '#' ) {
hex = hex.substr(1,6);
}
for ( var i = 0; i < 3; i ++) {
rgbOutput[i] = parseInt(hex.substr(2*i, 2), 16);
}
// returns [r,g,b] array
return rgbOutput;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment