Search code examples
javascriptcolorshsvhslhsb

Convert HSB/HSV color to HSL


How do I convert HSB color to HSL?

Photoshop shows HSB color in its color picker. HSB color cannot be used in CSS, but HSL can.

I tried this JS:

function hsb2hsl(h, s, b) {
  return {
    h: h,
    s: s,
    l: b-s/2
  }
}

But hsb2hsl(0, 100, 50).l == 0 instead of 25

Update: Can I do that without converting HSB → RGB → HSL?


Solution

  • I'm afraid my Javascript knowledge is lacking, but you should be able to infer the conversion from http://ariya.blogspot.com/2008/07/converting-between-hsl-and-hsv.html