Skip to content

Instantly share code, notes, and snippets.

@nowk
Created October 30, 2011 16:35
Show Gist options
  • Save nowk/1326091 to your computer and use it in GitHub Desktop.
Save nowk/1326091 to your computer and use it in GitHub Desktop.
function rgb2hex(rgb) {
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
function hex(x) {
return ("0" + parseInt(x).toString(16)).slice(-2);
}
return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment