PHP Class ariColor, kirki

Show file Open project: aristath/kirki Class Usage Examples

Public Properties

Property Type Description
$alpha integer | float
$blue integer | double
$brightness array
$chroma integer | float
$color string | array The color as defined in the input
$green integer | double
$hex string The HEX value of the color.
$hue integer | float
$instances array Each instance is stored as an object in this array. Allows easier access & performance.
$lightness integer | float
$luminance integer | float
$mode string The mode of this color (hex/rgb/rgba etc.).
$red integer | double
$saturation integer | float
$word_colors array Example: white = #ffffff

Public Methods

Method Description
getNew ( $property = '', $value = '' ) : ariColor | null Allows us to get a new instance by modifying a property of the existing one.
get_mode ( string $color ) : string | null Figure out what mode we're using.
newColor ( $color, $mode = 'auto' ) : ariColor Gets an instance for this color.
toCSS ( $mode = 'hex' ) : string Returns a CSS-formatted value for colors.

Private Methods

Method Description
__construct ( $color = '', $mode = 'auto' ) The class constructor
dexhex_double_digit ( $value ) : string Convert a decimal value to hex and make sure it's 2 characters
from_hex ( ) : void Starts with a HEX color and calculates all other properties.
from_hsl ( ) : void Starts with an HSL color and calculates all other properties.
from_hsl_array ( ) Calculates the red, green, blue values of an HSL color
from_hsla ( ) : void Starts with an HSLA color and calculates all other properties.
from_rgb ( ) : void Starts with an RGB color and calculates all other properties.
from_rgba ( ) : void Starts with an RGBA color and calculates all other properties.
get_word_colors ( ) : array Gets an array of all the wordcolors
rgb_to_hex ( $red, $green, $blue ) : string Generates the HEX value of a color given values for $red, $green, $blue
set_brightness ( ) Sets the brightness of a color based on the values of red, green, blue
set_hsl ( ) Sets the HSL values of a color based on the values of red, green, blue
set_luminance ( ) Sets the luminance of a color (range:0-255) based on the values of red, green, blue

Method Details

getNew() public method

Allows us to get a new instance by modifying a property of the existing one.
public getNew ( $property = '', $value = '' ) : ariColor | null
$property string can be one of the following: red, green, blue, alpha, hue, saturation, lightness, brightness
$value int|float|string the new value
return ariColor | null

get_mode() public method

Figure out what mode we're using.
public get_mode ( string $color ) : string | null
$color string
return string | null

newColor() public static method

We use a separate instance per color because there's no need to create a completely new instance each time we call this class. Instead using instances helps us improve performance & footprint.
public static newColor ( $color, $mode = 'auto' ) : ariColor
$color string|array
$mode string
return ariColor (object)

toCSS() public method

Returns a CSS-formatted value for colors.
public toCSS ( $mode = 'hex' ) : string
$mode string
return string

Property Details

$alpha public property

public int|float $alpha
return integer | float

$blue public property

public int|double $blue
return integer | double

$brightness public property

public array $brightness
return array

$chroma public property

public int|float $chroma
return integer | float

$color public property

The color as defined in the input
public string|array $color
return string | array

$green public property

public int|double $green
return integer | double

$hex public property

The HEX value of the color.
public string $hex
return string

$hue public property

public int|float $hue
return integer | float

$instances public static property

Each instance is stored as an object in this array. Allows easier access & performance.
public static array $instances
return array

$lightness public property

public int|float $lightness
return integer | float

$luminance public property

public int|float $luminance
return integer | float

$mode public property

The mode of this color (hex/rgb/rgba etc.).
public string $mode
return string

$red public property

public int|double $red
return integer | double

$saturation public property

public int|float $saturation
return integer | float

$word_colors public property

Example: white = #ffffff
public array $word_colors
return array