Skip to content

Instantly share code, notes, and snippets.

@gh-o-st
Last active November 11, 2020 17:46
Show Gist options
  • Save gh-o-st/3497f679352fba727a0f to your computer and use it in GitHub Desktop.
Save gh-o-st/3497f679352fba727a0f to your computer and use it in GitHub Desktop.
Turns an RGB color to hex
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;
};
<?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