Properties

$color

$color : int

Type

int

Methods

__construct()

__construct(string|array $color, string $type)

Initialize object

Parameters

string|array $color

A color of the type $type

string $type

The type of color we will construct from. One of hex (default), rgb, hsl, int

fromHex()

fromHex(string $hexValue) : \Jetpack_Color

Init color from hex value

Parameters

string $hexValue

Returns

\Jetpack_Color

fromRgbInt()

fromRgbInt(int $red, int $green, int $blue) : \Jetpack_Color

Init color from integer RGB values

Parameters

int $red
int $green
int $blue

Returns

\Jetpack_Color

fromRgbHex()

fromRgbHex(string $red, string $green, string $blue) : \Jetpack_Color

Init color from hex RGB values

Parameters

string $red
string $green
string $blue

Returns

\Jetpack_Color

fromHsl()

fromHsl(int $h, \in $s, int $l)

Converts an HSL color value to RGB. Conversion formula adapted from http://en.wikipedia.org/wiki/HSL_color_space.

Parameters

int $h

Hue. [0-360]

\in $s

Saturation [0, 100]

int $l

Lightness [0, 100]

fromInt()

fromInt(int $intValue) : \Jetpack_Color

Init color from integer value

Parameters

int $intValue

Returns

\Jetpack_Color

toHex()

toHex() : string

Convert color to hex

Returns

string

toRgbInt()

toRgbInt() : array

Convert color to RGB array (integer values)

Returns

array

toRgbHex()

toRgbHex() : array

Convert color to RGB array (hex values)

Returns

array

toHsvFloat()

toHsvFloat() : array

Get Hue/Saturation/Value for the current color (float values, slow but accurate)

Returns

array

toHsvInt()

toHsvInt() : int

Get HSV values for color (integer values from 0-255, fast but less accurate)

Returns

int

toHsl()

toHsl() : Array

Converts an RGB color value to HSL. Conversion formula adapted from http://en.wikipedia.org/wiki/HSL_color_space.

Assumes r, g, and b are contained in the set [0, 255] and returns h in [0, 360], s in [0, 100], l in [0, 100]

Returns

Array —

The HSL representation

toCSS()

toCSS( $type,  $alpha)

Parameters

$type
$alpha

toXyz()

toXyz() : array

Get current color in XYZ format

Returns

array

toLabCie()

toLabCie() : array

Get color CIE-Lab values

Returns

array

toInt()

toInt() : int

Convert color to integer

Returns

int

__toString()

__toString() : string

Alias of toString()

Returns

string

toString()

toString() : string

Get color as string

Returns

string

getDistanceRgbFrom()

getDistanceRgbFrom(\Jetpack_Color $color) : int

Get the distance between this color and the given color

Parameters

\Jetpack_Color $color

Returns

int

getDistanceLabFrom()

getDistanceLabFrom(\Jetpack_Color $color) : float

Get distance from the given color using the Delta E method

Parameters

\Jetpack_Color $color

Returns

float

toLuminosity()

toLuminosity()

getDistanceLuminosityFrom()

getDistanceLuminosityFrom(\Jetpack_Color $color) : float

Get distance between colors using luminance.

Should be more than 5 for readable contrast

Parameters

\Jetpack_Color $color

Another color

Returns

float

getMaxContrastColor()

getMaxContrastColor()

getGrayscaleContrastingColor()

getGrayscaleContrastingColor( $contrast)

Parameters

$contrast

getReadableContrastingColor()

getReadableContrastingColor(object $bg_color, integer $min_contrast) : object

Gets a readable contrasting color. $this is assumed to be the text and $color the background color.

Parameters

object $bg_color

A Color object that will be compared against $this

integer $min_contrast

The minimum contrast to achieve, if possible.

Returns

object —

A Color object, an increased contrast $this compared against $bg_color

isGrayscale()

isGrayscale( $threshold) : bool

Detect if color is grayscale

Parameters

$threshold

Returns

bool

getClosestMatch()

getClosestMatch(array $colors) : mixed

Get the closest matching color from the given array of colors

Parameters

array $colors

array of integers or Jetpack_Color objects

Returns

mixed —

the array key of the matched color

darken()

darken( $amount)

Parameters

$amount

lighten()

lighten( $amount)

Parameters

$amount

incrementLightness()

incrementLightness( $amount)

Parameters

$amount

saturate()

saturate( $amount)

Parameters

$amount

desaturate()

desaturate( $amount)

Parameters

$amount

incrementSaturation()

incrementSaturation( $amount)

Parameters

$amount

toGrayscale()

toGrayscale()

getComplement()

getComplement()

getSplitComplement()

getSplitComplement( $step)

Parameters

$step

getAnalog()

getAnalog( $step)

Parameters

$step

getTetrad()

getTetrad( $step)

Parameters

$step

getTriad()

getTriad( $step)

Parameters

$step

incrementHue()

incrementHue( $amount)

Parameters

$amount

hue2rgb()

hue2rgb( $p,  $q,  $t)

Helper function for Jetpack_Color::fromHsl()

Parameters

$p
$q
$t