Detect a palette harmony

Classify a palette by comparing its perceptual hue angles with known harmony patterns.

Pass an existing palette to HarmonyDetector and inspect both the pattern and confidence:

use PhpColor\Color\Color;
use PhpColor\Color\Palette\Harmony\HarmonyDetector;
use PhpColor\Color\Palette\Harmony\HarmonyGenerator;
use PhpColor\Color\Palette\Harmony\HarmonyPattern;

$palette = (new HarmonyGenerator())->generate(
    Color::parse('oklch(0.68 0.14 30)'),
    HarmonyPattern::Triadic,
);

$result = (new HarmonyDetector())->detect($palette);

assert(HarmonyPattern::Triadic === $result['type']);
assert(1.0 === $result['confidence']);
use PhpColor\Color\Color; use PhpColor\Color\Palette\Harmony\HarmonyDetector; use PhpColor\Color\Palette\Harmony\HarmonyGenerator; use PhpColor\Color\Palette\Harmony\HarmonyPattern; $palette = (new HarmonyGenerator())->generate( Color::parse('oklch(0.68 0.14 30)'), HarmonyPattern::Triadic, ); $result = (new HarmonyDetector())->detect($palette); assert(HarmonyPattern::Triadic === $result['type']); assert(1.0 === $result['confidence']);

Detection is a hue-geometry heuristic with a configurable tolerance. It does not judge contrast, color meaning, or visual balance.

See harmony detection or HarmonyDetector.