RALColor
Renfordt\Colors\RALColor
Represents a color from the RAL classic system. Holds a RAL code and resolves it through a built-in lookup table mapping codes to hex values.
Properties
| Property | Type | Notes |
|---|---|---|
ral | int | The RAL code. Stored without range validation. |
Static methods
create(string|int $ralStr): RALColor
Creates an instance from a RAL code. The value is cast to int.
$ral = RALColor::create(3020);
$ral = RALColor::create('3020');
make(string $ralStr): RALColor
Alias of create().
Instance methods
toHex(): HexColor
Resolves the RAL code against the lookup table and returns the corresponding
HexColor. Accessing a code that is not in the table will fail.
toRGB(): RGBColor
Converts to RGBColor via hex.
toHSL(): HSLColor
Converts to HSLColor via hex. No precision parameter; uses the default.
toHSV(): HSVColor
Converts to HSVColor via hex. No precision parameter; uses the default.
findClosestColor(HexColor $target): ?RALColor
Returns the RALColor whose lookup-table entry is closest to $target, measured
as the Euclidean distance in RGB space. Returns null only if the lookup table
is empty.
$closest = RALColor::create(3020)
->findClosestColor(HexColor::create('#FF5500'));
echo $closest->ral;
Example
$ral = RALColor::create(3020);
$hex = $ral->toHex();
$rgb = $ral->toRGB();
$hsl = $ral->toHSL();