Created
August 11, 2015 03:36
-
-
Save JavaScript-Packer/4a5d9fe5cf7f6e2d52ba to your computer and use it in GitHub Desktop.
RGB to HEX color converter
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 rgb2hex(s) { | |
| return (s = s.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i)) && 4 === s.length ? "#" + ("0" + parseInt(s[1], 10).toString(16)).slice(-2) + ("0" + parseInt(s[2], 10).toString(16)).slice(-2) + ("0" + parseInt(s[3], 10).toString(16)).slice(-2) : ""; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment