Convert, manipulate, and generate color schemes across all major color spaces — with a clean, chainable PHP API.
composer require wwaz/colormodel-php- 10 color models — HEX, RGB, RGBA, HSB, HSV, HSL, CMYK, CMYKInt, CIELab, CIELCh, XYZ
- Fluent conversions — chain from one color space to another in a single expression
- Color manipulation — rotate hue, mix colors with custom weights
- Color schemes — Complementary, Triadic, Tetradic, Square, Analogous, Tint, Tone, Shade
- Flexible input/output — accept strings, arrays, integers, or named colors like
'red'
Start with a HEX color, rotate its hue by 180°, and export as CMYK — perfect for generating print-ready complementary colors from web values:
use wwaz\Colormodel\Model\Hex;
$cmyk = (new Hex('#f00'))
->hue(180)
->toCMYK();
echo $cmyk->toString(); // 100,0,0,0
echo $cmyk->toHtml(); // cmyk(100,0,0,0)
echo $cmyk->toArray(); // [100, 0, 0, 0]Blend two colors in any ratio. Great for generating palette gradients or brand color variations programmatically:
use wwaz\Colormodel\Model\Hex;
$red = new Hex('#ff0000');
$blue = new Hex('#0000ff');
// 50/50 mix → purple
echo $red->mix($blue)->toString(); // 800080
// 75/25 mix (more red) → darker pink
echo $red->mix($blue, 0.25)->toString(); // BF0040Feed in any color, get back a complete set of harmonious variations — all returned in the same color model you started with:
use wwaz\Colormodel\Model\RGB;
use wwaz\Colormodel\Scheme\Complementary;
use wwaz\Colormodel\Scheme\Triadic;
use wwaz\Colormodel\Scheme\Analogous;
use wwaz\Colormodel\Scheme\Tint;
$base = new RGB(255, 0, 0); // red
(new Complementary($base))->get(); // ['255,0,0', '0,255,255']
(new Triadic($base))->get(); // red + 2 harmonics
(new Analogous($base))->get(); // neighboring hues
(new Tint($base))->get(); // lighter variations
// Works with CMYK too — output stays in CMYK
use wwaz\Colormodel\Model\CMYKInt;
$cyan = new CMYKInt(100, 0, 0, 0);
(new Complementary($cyan))->get(); // ['100,0,0,0', '0,100,100,0']| Model | Channels | Typical use |
|---|---|---|
| HEX | #RRGGBB | HTML / CSS |
| RGB | 0–255 per channel | Screen / digital |
| RGBA | RGB + alpha (0–1) | CSS with transparency |
| HSB/HSV | Hue 0–360°, Sat 0–100, Bri 0–100 | Color pickers |
| HSL | Hue 0–360°, Sat 0–100, Lig 0–100 | CSS / design tools |
| CMYK | 0–1 float per channel | Print (float) |
| CMYKInt | 0–100 int per channel | Print (integer) |
| CIELab | L 0–100, a, b axes | Perceptual color science |
| CIELCh | L, Chroma, Hue | Smooth color gradients |
| XYZ | Device-independent reference | Color math / ICC |
composer installcomposer checkYou can also run the checks individually:
composer test
composer analyse
composer lint- Existing public APIs are kept backward-compatible.
- Legacy usage with
new HEX(...)remains supported. - New APIs are added in an additive way to avoid breaking existing integrations.
Please see CONTRIBUTING.md for development workflow and pull request expectations.
MIT