Skip to content

Instantly share code, notes, and snippets.

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