Last active
November 11, 2020 17:46
-
-
Save gh-o-st/3497f679352fba727a0f to your computer and use it in GitHub Desktop.
Turns an RGB color to hex
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
const rgb2hex = function(r, g, b) { | |
return hexify(r).hexify(g).hexify(b); | |
}; | |
const hexify = function(num) { | |
let hex = num.toString(16); | |
return hex.length == 1 ? "0" + hex : hex; | |
}; |
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
<?php | |
function rgb2hex($r, $g, $b) { | |
return sprintf("#%02x%02x%02x", $r, $g, $b); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment