Documentation

Colors
in package

Author: Arlo Carreon <http://arlocarreon.com> Info: http://mexitek.github.io/phpColors/ License: http://arlo.mit-license.org/

Table of Contents

Constants

DEFAULT_ADJUST  = 10
Auto darkens/lightens by 10% for sexily-subtle gradients.

Properties

$_hex  : mixed
$_hsl  : mixed
$_rgb  : mixed

Methods

__construct()  : mixed
Instantiates the class with a HEX value
__get()  : mixed
__set()  : mixed
__toString()  : string
Converts object into its string representation
complementary()  : string
Returns the complimentary color
darken()  : string
Given a HEX value, returns a darker color. If no desired amount provided, then the color halfway between given HEX and black will be returned.
getCssGradient()  : string
Returns the cross browser CSS3 gradient
getHex()  : mixed
Returns your original color
getHsl()  : mixed
Returns your color's HSL array
getRgb()  : mixed
Returns your color's RGB array
hexToHsl()  : array<string|int, mixed>
Given a HEX string returns a HSL array equivalent.
hexToRgb()  : array<string|int, mixed>
Given a HEX string returns a RGB array equivalent.
hslToHex()  : string
Given a HSL associative array returns the equivalent HEX string
isDark()  : bool
Returns whether or not a given color is considered "dark"
isLight()  : bool
Returns whether or not given color is considered "light"
lighten()  : string
Given a HEX value, returns a lighter color. If no desired amount provided, then the color halfway between given HEX and white will be returned.
makeGradient()  : array<string|int, mixed>
Creates an array with two shades that can be used to make a gradient
mix()  : string
Given a HEX value, returns a mixed color. If no desired amount provided, then the color mixed by this ratio
rgbToHex()  : string
Given an RGB associative array returns the equivalent HEX string
_checkHex()  : string
You need to check if you were given a good hex string
_darken()  : array<string|int, mixed>
Darkens a given HSL array
_huetorgb()  : int
Given a Hue, returns corresponding RGB value
_lighten()  : array<string|int, mixed>
Lightens a given HSL array
_mix()  : array<string|int, mixed>
Mix 2 rgb colors and return an rgb color

Constants

DEFAULT_ADJUST

Auto darkens/lightens by 10% for sexily-subtle gradients.

public mixed DEFAULT_ADJUST = 10

Set this to FALSE to adjust automatic shade to be between given color and black (for darken) or white (for lighten)

Properties

Methods

__construct()

Instantiates the class with a HEX value

public __construct(string $hex) : mixed
Parameters
$hex : string
Tags
throws
Exception

"Bad color format"

__get()

public __get(mixed $name) : mixed
Parameters
$name : mixed

__set()

public __set(mixed $name, mixed $value) : mixed
Parameters
$name : mixed
$value : mixed

__toString()

Converts object into its string representation

public __toString() : string
Return values
string

Color

complementary()

Returns the complimentary color

public complementary() : string
Return values
string

Complementary hex color

darken()

Given a HEX value, returns a darker color. If no desired amount provided, then the color halfway between given HEX and black will be returned.

public darken([int $amount = self::DEFAULT_ADJUST ]) : string
Parameters
$amount : int = self::DEFAULT_ADJUST
Return values
string

Darker HEX value

getCssGradient()

Returns the cross browser CSS3 gradient

public getCssGradient([int $amount = self::DEFAULT_ADJUST ][, bool $vintageBrowsers = FALSE ][, string $suffix = "" ][, string $prefix = "" ]) : string
Parameters
$amount : int = self::DEFAULT_ADJUST

Optional: percentage amount to light/darken the gradient

$vintageBrowsers : bool = FALSE

Optional: include vendor prefixes for browsers that almost died out already

$suffix : string = ""

Optional: suffix for every lines

$prefix : string = ""

Optional: prefix for every lines

Tags
link

Resource for the browser support

Return values
string

CSS3 gradient for chrome, safari, firefox, opera and IE10

getHex()

Returns your original color

public getHex() : mixed

getHsl()

Returns your color's HSL array

public getHsl() : mixed

getRgb()

Returns your color's RGB array

public getRgb() : mixed

hexToHsl()

Given a HEX string returns a HSL array equivalent.

public static hexToHsl(string $color) : array<string|int, mixed>
Parameters
$color : string
Return values
array<string|int, mixed>

HSL associative array

hexToRgb()

Given a HEX string returns a RGB array equivalent.

public static hexToRgb(string $color) : array<string|int, mixed>
Parameters
$color : string
Return values
array<string|int, mixed>

RGB associative array

hslToHex()

Given a HSL associative array returns the equivalent HEX string

public static hslToHex([array<string|int, mixed> $hsl = array() ]) : string
Parameters
$hsl : array<string|int, mixed> = array()
Tags
throws
Exception

"Bad HSL Array"

Return values
string

HEX string

isDark()

Returns whether or not a given color is considered "dark"

public isDark([string|bool $color = FALSE ][, int $darkerThan = 130 ]) : bool
Parameters
$color : string|bool = FALSE
$darkerThan : int = 130
Return values
bool

isLight()

Returns whether or not given color is considered "light"

public isLight([string|bool $color = FALSE ][, int $lighterThan = 130 ]) : bool
Parameters
$color : string|bool = FALSE
$lighterThan : int = 130
Return values
bool

lighten()

Given a HEX value, returns a lighter color. If no desired amount provided, then the color halfway between given HEX and white will be returned.

public lighten([int $amount = self::DEFAULT_ADJUST ]) : string
Parameters
$amount : int = self::DEFAULT_ADJUST
Return values
string

Lighter HEX value

makeGradient()

Creates an array with two shades that can be used to make a gradient

public makeGradient([int $amount = self::DEFAULT_ADJUST ]) : array<string|int, mixed>
Parameters
$amount : int = self::DEFAULT_ADJUST

Optional percentage amount you want your contrast color

Return values
array<string|int, mixed>

An array with a 'light' and 'dark' index

mix()

Given a HEX value, returns a mixed color. If no desired amount provided, then the color mixed by this ratio

public mix(string $hex2[, int $amount = 0 ]) : string
Parameters
$hex2 : string

Secondary HEX value to mix with

$amount : int = 0

= -100..0..+100

Return values
string

mixed HEX value

rgbToHex()

Given an RGB associative array returns the equivalent HEX string

public static rgbToHex([array<string|int, mixed> $rgb = array() ]) : string
Parameters
$rgb : array<string|int, mixed> = array()
Tags
throws
Exception

"Bad RGB Array"

Return values
string

RGB string

_checkHex()

You need to check if you were given a good hex string

private static _checkHex(string $hex) : string
Parameters
$hex : string
Tags
throws
Exception

"Bad color format"

Return values
string

Color

_darken()

Darkens a given HSL array

private _darken(array<string|int, mixed> $hsl[, int $amount = self::DEFAULT_ADJUST ]) : array<string|int, mixed>
Parameters
$hsl : array<string|int, mixed>
$amount : int = self::DEFAULT_ADJUST
Return values
array<string|int, mixed>

$hsl

_huetorgb()

Given a Hue, returns corresponding RGB value

private static _huetorgb(int $v1, int $v2, int $vH) : int
Parameters
$v1 : int
$v2 : int
$vH : int
Return values
int

_lighten()

Lightens a given HSL array

private _lighten(array<string|int, mixed> $hsl[, int $amount = self::DEFAULT_ADJUST ]) : array<string|int, mixed>
Parameters
$hsl : array<string|int, mixed>
$amount : int = self::DEFAULT_ADJUST
Return values
array<string|int, mixed>

$hsl

_mix()

Mix 2 rgb colors and return an rgb color

private _mix(array<string|int, mixed> $rgb1, array<string|int, mixed> $rgb2[, int $amount = 0 ]) : array<string|int, mixed>
Parameters
$rgb1 : array<string|int, mixed>
$rgb2 : array<string|int, mixed>
$amount : int = 0

ranged -100..0..+100

Return values
array<string|int, mixed>

$rgb

ported from http://phpxref.pagelines.com/nav.html?includes/class.colors.php.source.html


        
On this page

Search results