Skip to content

Instantly share code, notes, and snippets.

@kparms
Created March 10, 2014 16:48
Show Gist options
  • Select an option

  • Save kparms/9468850 to your computer and use it in GitHub Desktop.

Select an option

Save kparms/9468850 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