Mix colors in a chosen space

Use one ratio with two interpolation spaces and see the exact difference in the resulting color.

Oklab
#806eae 0.5 #d97706 #ac7776
OklabColor
Linear-light sRGB
#806eae 0.5 #d97706 #ad735a
SrgbColor

The interpolation space changes the result

The endpoints and ratio stay fixed. Oklab and linear-light sRGB take different paths between them and return different concrete color types.

Choose the space explicitly

Oklab is the default. The srgb option interpolates linearized sRGB channels rather than encoded channel numbers.

<?php

use PhpColor\Color\Color;

$source = Color::parse('#806eae');
$other = Color::parse('#d97706');

$oklab = Color::mix($source, $other, 0.5, 'oklab');
$srgb = Color::mix($source, $other, 0.5, 'srgb');

echo $oklab->toHex(); // #ac7776
echo $srgb->toHex();  // #ad735a
use PhpColor\Color\Color; $source = Color::parse('#806eae'); $other = Color::parse('#d97706'); $oklab = Color::mix($source, $other, 0.5, 'oklab'); $srgb = Color::mix($source, $other, 0.5, 'srgb'); echo $oklab->toHex(); // #ac7776 echo $srgb->toHex(); // #ad735a

Use a gradient for a complete path

Color::mix() returns one point between two endpoints. Gradients add multiple stops, geometry, and repeated sampling. Mixing is also distinct from alpha compositing and blend modes.

Two interpolation names

Only oklab and srgb are supported. Names such as oklch, rgb, srgb-linear, and lab throw.

Clamped ratio

The ratio clamps to 0..1. Alpha interpolates linearly, and hexadecimal serialization quantizes the final channels.

Try another pair

Choose a space, then inspect the exact mixed color