RAL colors and matching
RALColor represents a color from the RAL classic system. Internally it holds a
RAL code and resolves it against a built-in lookup table that maps each code to a
hex value.
Creating a RAL color
use Renfordt\Colors\RALColor;
$ral = RALColor::create(3020); // accepts int or numeric string
echo $ral->ral; // 3020
The RAL code is stored as-is without range validation. Converting a code that is not present in the lookup table will fail when the table is accessed.
Converting from RAL
RAL colors convert to hex through the lookup table, and to other formats through hex:
$ral = RALColor::create(3020);
$hex = $ral->toHex(); // HexColor
$rgb = $ral->toRGB(); // RGBColor
$hsl = $ral->toHSL(); // HSLColor
$hsv = $ral->toHSV(); // HSVColor
Finding the closest RAL color
findClosestColor() takes a HexColor and returns the RALColor whose entry in
the lookup table is nearest to it. Distance is the Euclidean distance between the
two colors in RGB space:
$ral = RALColor::create(3020);
$target = HexColor::create('#FF5500');
$closest = $ral->findClosestColor($target); // RALColor
echo $closest->ral;
The method compares the target against every entry in the table and returns the
closest match. It returns null only if the lookup table is empty, which does
not occur with the built-in table.