CRM_Utils_Color
in package
Static utility functions for working with colors
Table of Contents
Constants
- COLOR_FILE = '[civicrm.root]/bower_components/css-color-names/css-color-names.json'
Methods
- getContrast() : string
- Determine the appropriate text color for a given background.
- getHighlight() : string
- Calculate a highlight color from a base color
- getRgb() : array<string|int, int>|null
- Parse any color string into rgb decimal values
- nameToHex() : string|null
- Convert named color (e.g. springgreen) to hex
- normalize() : bool
- Validate color input and convert it to standard hex notation
- rgbToHex() : string
- Converts rgb array to hex string
Constants
COLOR_FILE
public
mixed
COLOR_FILE
= '[civicrm.root]/bower_components/css-color-names/css-color-names.json'
Methods
getContrast()
Determine the appropriate text color for a given background.
public
static getContrast(string $color[, string $black = 'black' ][, string $white = 'white' ]) : string
Based on YIQ value.
Parameters
- $color : string
- $black : string = 'black'
- $white : string = 'white'
Return values
stringgetHighlight()
Calculate a highlight color from a base color
public
static getHighlight(string $color) : string
Parameters
- $color : string
Return values
stringgetRgb()
Parse any color string into rgb decimal values
public
static getRgb(string $color) : array<string|int, int>|null
Accepted formats: Full hex: "#ffffff" Short hex: "#fff" Color name "white" RGB notation: "rgb(255, 255, 255)"
Parameters
- $color : string
Return values
array<string|int, int>|null —[red, green, blue]
nameToHex()
Convert named color (e.g. springgreen) to hex
public
static nameToHex(string $colorName) : string|null
Parameters
- $colorName : string
Return values
string|nullnormalize()
Validate color input and convert it to standard hex notation
public
static normalize(string &$color) : bool
Parameters
- $color : string
Return values
boolrgbToHex()
Converts rgb array to hex string
public
static rgbToHex(array<string|int, int> $rgb) : string
Parameters
- $rgb : array<string|int, int>