Created
June 24, 2012 17:58
-
-
Save zapnap/2984189 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function colorToHex(color) { | |
if (color.substr(0, 1) === '#') { | |
return color; | |
} | |
var digits = /(.*?)rgb\((\d+), (\d+), (\d+)\)/.exec(color); | |
var red = parseInt(digits[2]); | |
var green = parseInt(digits[3]); | |
var blue = parseInt(digits[4]); | |
var rgb = blue | (green << 8) | (red << 16); | |
return digits[1] + '#' + rgb.toString(16); | |
}; | |
colorToHex('rgb(120, 120, 240)') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment