Skip to content

Instantly share code, notes, and snippets.

@dgalarza
Created December 5, 2010 04:17
Show Gist options
  • Save dgalarza/728785 to your computer and use it in GitHub Desktop.
Save dgalarza/728785 to your computer and use it in GitHub Desktop.
Converts an object representation of an RGB color to a hex string
/**
* Takes an RGB object and converts it into a hex string
*
* @param {Object} RGB Colors {r:255, g:255, b:255}
*/
var rgbToHex = function(rgb) {
var hex = rgb.b | (rgb.g << 8) | (rgb.r << 16);
return hex.toString(16); // 'FFFFFF'
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment