Invert color channels
Replace each encoded sRGB channel with its complement while preserving alpha.
Source
124, 58, 237
#7c3aed
Inverted
131, 197, 18
#83c512
Inverted twice
124, 58, 237
#7c3aed
Complement every encoded RGB channel
Each channel becomes 1 minus its sRGB value. Applying the same operation twice returns this hexadecimal fixture to its source value.
Invert without replacing the source
invert() works through sRGB and converts the result back to the concrete type on which it was called.
<?php
use PhpColor\Color\Color;
$source = Color::parse('#7c3aed');
$inverted = $source->invert();
printf("%s\n%s\n",
$inverted->toHex(),
$inverted->invert()->toHex(),
);
// #83c512
// #7c3aed
use PhpColor\Color\Color;
$source = Color::parse('#7c3aed');
$inverted = $source->invert();
printf("%s\n%s\n",
$inverted->toHex(),
$inverted->invert()->toHex(),
);
// #83c512
// #7c3aed
Do not confuse inversion with a theme
Channel inversion is deterministic arithmetic. It does not infer semantic roles, preserve contrast, or create a dark-mode palette.
SpaceThe inversion itself operates on encoded sRGB channels.
AlphaThe source alpha is retained.
TypeThe result is converted back to the source object type.
SemanticsA complement is not automatically a usable interface token.