sunasty / color-math
Zero-dependency sRGB, OKLCH, and WCAG 2.1 contrast calculation in PHP
v1.0.1
2026-10-24 11:10 UTC
Requires
- php: >=8.1
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Zero-dependency PHP library for sRGB, OKLCH, relative luminance, and WCAG 2.1 accessibility contrast calculation.
Originally designed for the Sunasty Color Picker client-side tool and the Sunasty Developer Tools.
Installation
composer require sunasty/color-math
Quick Start
use Sunasty\ColorMath\ColorMath; // Parse hex colors $teal = ColorMath::hexToRgb('#0F766E'); $white = [255, 255, 255]; // Compute WCAG contrast $ratio = ColorMath::contrastRatio($teal, $white); $wcag = ColorMath::checkWcag($ratio); echo "Contrast: {$ratio}:1\n"; echo "Passes AA: " . ($wcag['aa_normal'] ? 'Yes' : 'No') . "\n";
Related Tools
- Sunasty Color Picker & Palette Extractor
- Sunasty Developer Utilities
- Sunasty Color Picker Chrome Extension
License
MIT © Bastien Sulyan