Skip to main content

HSVColor

Renfordt\Colors\HSVColor

Represents a color as hue, saturation, and value. Uses Renfordt\Colors\Traits\HueBasedTrait for its RGB conversion.

Properties

PropertyTypeRangeNotes
hueint0–360Clamped on assignment
saturationfloat0.0–1.0Clamped on assignment
valuefloat0.0–1.0Clamped on assignment
alphafloat0.0–1.0Opacity; 1.0 = opaque. Defaults to 1.0. Clamped on assignment

Static methods

create(array $hsv): HSVColor

Creates an instance from [hue, saturation, value], with an optional 4th alpha element. Alpha defaults to 1.0 (opaque) when omitted.

$hsv = HSVColor::create([240, 0.8, 0.6]);
$hsva = HSVColor::create([240, 0.8, 0.6, 0.5]); // 50% opaque

make(array $hsv): HSVColor

Alias of create().

Instance methods

getHSV(): array

Returns the components as [hue, saturation, value] (alpha excluded).

getHSVA(): array

Returns the components as [hue, saturation, value, alpha].

toRGB(): RGBColor

Converts to RGBColor using chroma derived from saturation and value. The 0.01.0 alpha is carried through as a 0255 int.

toHex(): HexColor

Converts to HexColor via RGB. Alpha is preserved.

Converting to HSL

There is no direct toHSL() method. Convert through RGB:

$hsl = HSVColor::create([240, 0.8, 0.6])->toRGB()->toHSL();

Adjusting brightness

HSVColor has no brighten() / darken() helpers. Assign the value property, which is clamped on assignment:

$hsv = HSVColor::create([240, 0.8, 0.6]);
$hsv->value = 0.9;