Skip to content

Instantly share code, notes, and snippets.

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