danmichaelo/coma
CoMa is a PHP color math library for converting between sRGB, XYZ and Lab color spaces and computing color difference (Delta E) metrics. Includes CIE76 and CIE94, with more planned. Suitable for matching and comparing colors.
ColorValidationService).class ValidatedColor
{
public static function fromHex(string $hex): sRGB
{
if (!preg_match('/^#[0-9A-F]{6}$/i', $hex)) {
throw new \InvalidArgumentException("Invalid HEX format");
}
$rgb = hexToRgb($hex);
return new sRGB($rgb['r'], $rgb['g'], $rgb['b']);
}
}
spatie/color (simpler, but fewer metrics).color-diff) if client-side previews are needed.colormath) if you’re open to multi-language stacks.GMP extension for arbitrary-precision arithmetic.round($deltaE, 2)).app/Services/ColorComparisonService) to:
namespace App\Services;
use Danmichaelo\Coma\{sRGB, ColorDistance};
use Illuminate\Support\Facades\Cache;
class ColorComparisonService
{
public function getDeltaE(string $hex1, string $hex2, string $metric = 'cie94'): float
{
$cacheKey = "delta_e_{$hex1}_{$hex2}_{$metric}";
return Cache::remember($cacheKey, now()->addHours(1), function () use ($hex1, $hex2, $metric) {
$color1 = ValidatedColor::fromHex($hex1);
$color2 = ValidatedColor::fromHex($hex2);
$cd = new ColorDistance();
return $cd->$metric($color1, $color2);
});
}
}
php artisan color:audit --palette=brand.json --threshold=5
{
"color1": "#FF0000",
"color2": "#CC0000",
"deltaE": 4.2,
"metric": "cie94",
"passesThreshold": true,
"threshold": 5.0
}
ColorComplianceFailed event):
if ($deltaE > $threshold) {
event(new ColorComplianceFailed($color1, $color2, $deltaE));
}
Phase 1: Proof of Concept (1–2 Days)
#808080).#000000 vs. #FFFFFF).#GHIJKL).#FF0000 vs. #00FF00 should yield a high ΔE).Phase 2: Core Integration (3–5 Days)
Phase 3: Expansion (Ongoing)
- name: Check Color Compliance
How can I help you explore Laravel packages today?