Transformation Chains

Compose conversion and adjustment steps into one readable workflow without mutating the source color.

Keep every transformation visible in one chain

Convert into the working space, set exact coordinates, apply relative changes, then return to the output space. The sequence documents the intent directly in code.

<?php

use PhpColor\Color\Color;

$button = Color::parse('#3b82f6')
    ->to('oklch')
    ->withChannel('l', 0.65)
    ->desaturate(0.03)
    ->rotateHue(-4)
    ->withAlpha(0.9)
    ->to('srgb');
use PhpColor\Color\Color; $button = Color::parse('#3b82f6') ->to('oklch') ->withChannel('l', 0.65) ->desaturate(0.03) ->rotateHue(-4) ->withAlpha(0.9) ->to('srgb');

Branch several states from the same source

A transformation never rewrites the receiver. Keep the parsed value as the stable source and derive hover, pressed, muted, or translucent variants independently.

SourceOne stable parsed value.
BranchesIndependent derived objects.

Separate perceptual work from delivery format

Use Oklch when the chain edits lightness, chroma, or hue. Convert only at clear boundaries so channel meaning and final serialization remain predictable.

sRGB input to('oklch') channel work relative adjustments to('srgb') CSS output

Transform a palette when the rule applies to every color

A palette exposes collection-wide conversion and adjustment methods. Use it instead of repeating the same chain manually for every related value.

<?php

use PhpColor\Color\Palette\ColorPalette;

$palette = ColorPalette::parse([
    '#1d4ed8', '#3b82f6', '#93c5fd',
]);

$derived = $palette
    ->to('oklch')
    ->lighten(0.04)
    ->rotateHue(-6);
use PhpColor\Color\Palette\ColorPalette; $palette = ColorPalette::parse([ '#1d4ed8', '#3b82f6', '#93c5fd', ]); $derived = $palette ->to('oklch') ->lighten(0.04) ->rotateHue(-6);

Go deeper

Turn color intent into a readable pipeline