Skip to content

Instantly share code, notes, and snippets.

@tabatkins
Forked from jonathantneal/RGB2HSL.js
Created March 19, 2012 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tabatkins/2122580 to your computer and use it in GitHub Desktop.
Save tabatkins/2122580 to your computer and use it in GitHub Desktop.
RGBA to HSLA
function RGBAtoHSLA(r, g, b, a) {
var
min = Math.min(r, g, b),
max = Math.max(r, g, b),
diff = max - min,
hsla = [0, 0, (min + max) / 2, a];
if (diff != 0) {
hsla[1] = hsla[2] < 0.5 ? diff / (max + min) : diff / (2 - max - min);
hsla[0] = (r == max ? (g - b) / diff : g == max ? 2 + (b - r) / diff : 4 + (r - g) / diff) * 60;
}
return hsla;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment