Created
July 2, 2010 15:17
-
-
Save Mottie/461493 to your computer and use it in GitHub Desktop.
Return Hex color from RGB format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Javascript function to convert rgb format to a hex color | |
* call : rgb2hex( "rgb(0, 70, 255)" ); | |
* returns: #0046ff | |
*/ | |
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
Removed internal function & its calls.