Compose from one color

Expand a single color into palettes, harmonies, and gradients.

Everything so far handled one color at a time. The composition APIs take one color in and hand structured sets back -- and since they all speak ColorInterface, anything from the previous steps feeds straight in.

Palettes and scales

ColorPalette expands a base into tonal ramps:

use PhpColor\Color\Color;
use PhpColor\Color\Palette\ColorPalette;

$blue = Color::parse('#3b82f6');

ColorPalette::tints($blue, 5);   // toward white
ColorPalette::shades($blue, 5);  // toward black
use PhpColor\Color\Color; use PhpColor\Color\Palette\ColorPalette; $blue = Color::parse('#3b82f6'); ColorPalette::tints($blue, 5); // toward white ColorPalette::shades($blue, 5); // toward black

base
#6ea3fb
#9ec3ff
#cee1ff
white

Harmonies

The classic wheel relationships, one call each, straight on the color object:

$blue->complementary();  // #c17400
$blue->triadic();        // [$blue, #e24956, #3ba01b]
$blue->analogous();      // [$blue, #886cee, #0097e1]
$blue->complementary(); // #c17400 $blue->triadic(); // [$blue, #e24956, #3ba01b] $blue->analogous(); // [$blue, #886cee, #0097e1]

base
triadic
triadic

Gradients

Gradient interpolates in OKLab, so midpoints stay vivid instead of dipping through gray. It emits CSS directly, or hands you any point on the ramp:

use PhpColor\Color\Gradient\Gradient;

$g = Gradient::linear(90, '#3b82f6', '#f43f5e');

$g->toCss();
// linear-gradient(90deg, rgb(59 130 246) 0%, rgb(244 63 94) 100%)

$g->interpolate(0.5)->toHex();
// #aa73ae
use PhpColor\Color\Gradient\Gradient; $g = Gradient::linear(90, '#3b82f6', '#f43f5e'); $g->toCss(); // linear-gradient(90deg, rgb(59 130 246) 0%, rgb(244 63 94) 100%) $g->interpolate(0.5)->toHex(); // #aa73ae

0.0
interpolate(0.5)
1.0

Go deeper: Palettes, harmonies, and gradients covers the builders, palette fixers, and CSS export.

From one color to palettes, harmonies, and gradients: the whole library now works for you. Now ship it.