Color Recipes

Focused, copyable PHPColor solutions for parsing, conversion, generation, transformation, composition, evaluation, and everyday PHP tasks.

Conversion

Convert HEX to RGB

Parse a hexadecimal color and emit CSS RGB or read its integer channels.

Conversion

Convert RGB to HEX

Turn RGB channels or a CSS rgb() value into hexadecimal output.

Conversion

Convert HEX to OKLCH

Convert an sRGB hexadecimal color to perceptual OKLCH coordinates.

Conversion

Convert RGB to CMYK

Convert an RGB or hexadecimal input to device-cmyk() and CMYK channels.

Conversion

Convert HEX to HSL

Format a hexadecimal sRGB color as CSS hsl() or read its HSL channels.

Parsing

Validate a submitted CSS color

Validate submitted CSS color text without exception-based control flow, then verify the accepted value survives a CSS serialization round trip.

Transformation

Create a translucent overlay token

Derive a translucent CSS token from an opaque color while preserving the tested color space and channels and leaving the source object unchanged.

Evaluation

Detect a palette harmony

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

Evaluation

Choose black or white text

Select whichever standard text color has the stronger WCAG contrast against a known background.

Transformation

Shift an entire palette hue

Rotate every palette color by the same perceptual hue angle while retaining token names.

Composition

Repair a triadic palette

Realign an uneven three-color palette to triadic hue angles while keeping its names and perceptual character.

Evaluation

Audit token contrast

Test the intentional foreground and background pairs in a token system instead of producing noise from every possible combination.