Skip to content

Instantly share code, notes, and snippets.

@sergi
Created March 16, 2010 16:20
Show Gist options
  • Save sergi/334165 to your computer and use it in GitHub Desktop.
Save sergi/334165 to your computer and use it in GitHub Desktop.
Converts hexadecimal colors to RGB color tuples
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