Created
March 16, 2010 16:20
-
-
Save sergi/334165 to your computer and use it in GitHub Desktop.
Converts hexadecimal colors to RGB color tuples
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
var hex2rgb = function(color) { | |
var r = color.match(/^#(([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2}))$/i); | |
if (!r) return [0, 0, 0, 255]; | |
return [parseInt(r[2], 16), | |
parseInt(r[3], 16), | |
parseInt(r[4], 16), 255]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment