Web

Web Color class Extension point: getColorObj().

Namespace: Com\Tecnick\Color

class Web extends Css implements ColorParserInterface

Extends: Css

Implements: ColorParserInterface

Source: src/Web.php:38

Web Color class

Extension point: getColorObj(). Every other public method is final.

Constants

WEBHEX

Maps WEB safe color names with their hexadecimal representation (#RRGGBBAA).

public const WEBHEX = ['aliceblue' => 'f0f8ffff', 'antiquewhite' => 'faebd7ff', 'aqua' => '00ffffff', 'aquamarine' => '7fffd4ff', 'azure' => 'f0ffffff', 'beige' => 'f5f5dcff', 'bisque' => 'ffe4c4ff', 'black' => '000000ff', 'blanchedalmond' => 'ffebcdff', 'blue' => '0000ffff', 'blueviolet' => '8a2be2ff', 'brown' => 'a52a2aff', 'burlywood' => 'deb887ff', 'cadetblue' => '5f9ea0ff', 'chartreuse' => '7fff00ff', 'chocolate' 
// … truncated, see source

Source: src/Web.php:59

Methods

extractHexCode()

Extract the hexadecimal code from the input string and add the alpha channel if missing

final public extractHexCode(string $hex): string

Parameters:

  • $hex (string): string containing the hexadecimal color hash (i.e. #RGB, #RGBA, #RRGGBB, #RRGGBBAA)

Returns: string: the hash code (e.g.: ‘40e0d0’)

Throws:

  • Exception: if the hash is not found or has an invalid format

Source: src/Web.php:268

getClosestWebColor()

Get the name of the closest web color

Nearness is the Euclidean distance in sRGB, which is not perceptually uniform; getClosestWebColorByDeltaE() gives a perceptual match. A missing component counts as 0, so an empty array matches black. Ties resolve to the first matching color name.

final public getClosestWebColor(array<string,float> $col): string

Parameters:

  • $col (array<string,float>): Color as RGB array (keys: ‘red’, ‘green’, ‘blue’)

Returns: string

Source: src/Web.php:463

getClosestWebColorByDeltaE()

Get the name of the perceptually closest web color.

Nearness is the CIE76 color difference in CIE Lab. Ties resolve to the first matching color name.

final public getClosestWebColorByDeltaE(array<string,float> $col): string

Parameters:

  • $col (array<string,float>): Color as Lab array (keys: ’lstar’, ‘astar’, ‘bstar’)

Returns: string

Source: src/Web.php:535

getClosestWebColorByDeltaEFromString()

Get the name of the perceptually closest web color from a color definition string.

final public getClosestWebColorByDeltaEFromString(string $color): string

Parameters:

  • $color (string): String containing web color definition

Returns: string

Source: src/Web.php:556

getClosestWebColorFromString()

Get the name of the closest web color from a color definition string.

final public getClosestWebColorFromString(string $color): string

Parameters:

  • $color (string): String containing web color definition

Returns: string

Source: src/Web.php:483

getColorObj()

Parse the input color string and return the corresponding color object

public getColorObj(string $color): ?Model

Parameters:

  • $color (string): String containing web color definition

Returns: ?Model

Throws:

  • Exception: if the hash is malformed, the name is unknown, the color function is unsupported or its syntax is invalid, or the expression cannot be evaluated

Source: src/Web.php:391

getHexFromName()

Get the color hexadecimal hash code from name

Everything up to and including the first dot is discarded, so the Acrobat JavaScript spelling ‘color.green’ resolves to ‘green’.

final public getHexFromName(string $name): string

Parameters:

  • $name (string): Name of the color to search (e.g.: ’turquoise’)

Returns: string: color hexadecimal code (e.g.: ‘40e0d0ff’)

Throws:

Source: src/Web.php:224

getLabSquareDistance()

Get the square of the CIE76 color difference between 2 Lab points.

final public getLabSquareDistance(array<string,float> $cola, array<string,float> $colb): float

Parameters:

  • $cola (array<string,float>): First color as Lab array
  • $colb (array<string,float>): Second color as Lab array

Returns: float

Source: src/Web.php:518

getNameFromHex()

Get the color name code from hexadecimal hash

final public getNameFromHex(string $hex): string

Parameters:

  • $hex (string): hexadecimal color hash (i.e. #RRGGBBAA)

Returns: string: color name

Throws:

Source: src/Web.php:249

getRgbObjFromHex()

Get the RGB color object from hexadecimal hash

final public getRgbObjFromHex(string $hex): Rgb

Parameters:

  • $hex (string): hexadecimal color hash (i.e. #RGB, #RGBA, #RRGGBB, #RRGGBBAA)

Returns: Rgb

Throws:

  • Exception: if the hash is malformed or has an unsupported length

Source: src/Web.php:312

getRgbObjFromName()

Get the RGB color object from color name

final public getRgbObjFromName(string $name): Rgb

Parameters:

  • $name (string): Color name

Returns: Rgb: object

Throws:

Source: src/Web.php:326

getRgbSquareDistance()

Get the square of the distance between 2 RGB points

final public getRgbSquareDistance(array<string,float> $cola, array<string,float> $colb): float

Parameters:

  • $cola (array<string,float>): First color as RGB array
  • $colb (array<string,float>): Second color as RGB array

Returns: float

Source: src/Web.php:444

normalizeValue()

Get the normalized value from [0..$max] to [0..1]

Delegates to ComponentNormalizer::normalize().

final public normalizeValue(mixed $value, int $max): float

Parameters:

  • $value (mixed): Value to convert
  • $max (int): Max input value (reference value), must be positive

Returns: float: value [0..1]

Source: src/Web.php:377

tryGetColorObj()

Parse the input color string, returning null instead of raising.

final public tryGetColorObj(string $color): ?Model

Parameters:

  • $color (string): String containing web color definition

Returns: ?Model

Source: src/Web.php:427

Inherited members

From Css