class CRM_Utils_Color

Static utility functions for working with colors

Constants

COLOR_FILE

Methods

static string
getContrast(string $color, string $black = 'black', string $white = 'white')

Determine the appropriate text color for a given background.

static int[]|null
getRgb(string $color)

Parse any color string into rgb decimal values

static string
getHighlight($color)

Calculate a highlight color from a base color

static string|null
nameToHex($colorName)

Convert named color (e.g. springgreen) to hex

static string
rgbToHex(int[] $rgb)

Converts rgb array to hex string

static bool
normalize(string $color)

Validate color input and convert it to standard hex notation

Details

at line 51
static string getContrast(string $color, string $black = 'black', string $white = 'white')

Determine the appropriate text color for a given background.

Based on YIQ value.

Parameters

string $color
string $black
string $white

Return Value

string

at line 70
static int[]|null getRgb(string $color)

Parse any color string into rgb decimal values

Accepted formats: Full hex: "#ffffff" Short hex: "#fff" Color name "white" RGB notation: "rgb(255, 255, 255)"

Parameters

string $color

Return Value

int[]|null [red, green, blue]

at line 96
static string getHighlight($color)

Calculate a highlight color from a base color

Parameters

$color

Return Value

string

at line 118
static string|null nameToHex($colorName)

Convert named color (e.g. springgreen) to hex

Parameters

$colorName

Return Value

string|null

at line 134
static string rgbToHex(int[] $rgb)

Converts rgb array to hex string

Parameters

int[] $rgb

Return Value

string

at line 148
static bool normalize(string $color)

Validate color input and convert it to standard hex notation

Parameters

string $color

Return Value

bool