HSLColor
Renfordt\Colors\HSLColor
Represents a color as hue, saturation, and lightness. Uses
Renfordt\Colors\Traits\HueBasedTrait for its RGB conversion.
Properties
| Property | Type | Range | Notes |
|---|---|---|---|
hue | int | 0–360 | Clamped on assignment |
saturation | float | 0.0–1.0 | Clamped on assignment |
lightness | float | 0.0–1.0 | Clamped on assignment |
alpha | float | 0.0–1.0 | Opacity; 1.0 = opaque. Defaults to 1.0. Clamped on assignment |
Static methods
create(array $hsl): HSLColor
Creates an instance from [hue, saturation, lightness], with an optional 4th
alpha element. Alpha defaults to 1.0 (opaque) when omitted.
$hsl = HSLColor::create([180, 0.5, 0.7]);
$hsla = HSLColor::create([180, 0.5, 0.7, 0.5]); // 50% opaque
make(array $hsl): HSLColor
Alias of create().
Instance methods
getHSL(): array
Returns the components as [hue, saturation, lightness] (alpha excluded).
getHSLA(): array
Returns the components as [hue, saturation, lightness, alpha].
brighten(int $amount = 10): void
Increases lightness by $amount / 100. The result is clamped to 0.0–1.0.
darken(int $amount = 10): void
Decreases lightness by $amount / 100. The result is clamped to 0.0–1.0.
toRGB(): RGBColor
Converts to RGBColor using chroma derived from saturation and lightness. The
0.0–1.0 alpha is carried through as a 0–255 int.
toHex(): HexColor
Converts to HexColor via RGB. Alpha is preserved.
Converting to HSV
There is no direct toHSV() method. Convert through RGB:
$hsv = HSLColor::create([180, 0.5, 0.7])->toRGB()->toHSV();
Example
$hsl = HSLColor::create([200, 0.6, 0.5]);
$hsl->brighten(20);
$hsl->darken(5);
$hex = $hsl->toHex();