Download the PHP package dustinwilson/pigmentum without Composer
On this page you can find all versions of the php package dustinwilson/pigmentum. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dustinwilson/pigmentum
More information about dustinwilson/pigmentum
Files in dustinwilson/pigmentum
Package pigmentum
Short Description Library for manipulating and converting between CIE Color spaces
License MIT
Informations about the package pigmentum
Pigmentum
Library for manipulating color in PHP. This is the result of my own experiments with color math. There are other color classes out there, but they either work not how I'd like or the math is incorrect.
Warning Before Using
This library is experimental. The code does not have any unit tests yet, but that work is planned. Until unit tests exist, treat this software as beta or even alpha software. Also, the public API is in flux, so if you do use this library you're forewarned of possible breaking API changes.
Requirements
- PHP 8.0.2 or newer with the following extensions:
- Composer 2.0 or newer
Documentation
Color in Pigmentum is represented as a single color object. All color spaces are converted to and representated as XYZ D50 2° internally. Currently Pigmentum handles the following color spaces:
Any color space supported in Pigmentum means that conversions to and from each color space is possible.
dW\Pigmentum\Color
Properties
- name (?string): A user-supplied name for the color. Useful when making palettes.
- workingSpaceRGB (string): The current RGB working space.
dW\Pigmentum\Color::withLab
Creates a new dW\Pigmentum\Color
object from L*a*b* values.
L
: The lightness channel valuea
: The a channel valueb
: The b channel valuename
: An optional name to associate with the color
Example
dW\Pigmentum\Color::withLCHab
Creates a new dW\Pigmentum\Color
object from L*C*H* (L*a*b*) values.
L
: The lightness channel valueC
: The chroma channel valueH
: The hue channel valuename
: An optional name to associate with the color
Example
dW\Pigmentum\Color::withRGB
Creates a new dW\Pigmentum\Color
object from RGB values.
R
: The red channel valueG
: The green channel valueB
: The blue channel valuename
: An optional name to associate with the colorprofile
: A string representation of the class name of the color profile the channel values are in, defaults to the current working space
Example
Outputs:
dW\Pigmentum\Color::withRGBHex
Creates a new dW\Pigmentum\Color
object from an RGB hex string.
hex
: An RGB hex string; can be preceded by a '#' or withoutname
: An optional name to associate with the colorprofile
: A string representation of the class name of the color profile the channel values are in, defaults to the current working space
Example
Outputs:
dW\Pigmentum\Color::withHSB
Creates a new dW\Pigmentum\Color
object from RGB values.
H
: The hue channel valueS
: The saturation channel valueB
: The brightness channel valuename
: An optional name to associate with the colorprofile
: A string representation of the class name of the color profile the channel values are in, defaults to the current working space
Example
dW\Pigmentum\Color::withXYZ
Creates a new dW\Pigmentum\Color
object from XYZ values.
X
: The X channel valueY
: The Y channel valueZ
: The Z channel valuename
: An optional name to associate with the color
Example
dW\Pigmentum\Color::toLab
Returns the L*a*b* color space for the color.
Example
Outputs:
dW\Pigmentum\Color::toRGB
Returns the RGB color space for the color.
profile
: A string representation of the class name of the color profile the channel values are in, defaults to the current working space
Example
Outputs:
dW\Pigmentum\Color::toXYZ
Returns the XYZ color space for the color.
Example
Outputs:
dW\Pigmentum\Color::average
Averages the provided colors in the L*a*b* color space and returns a new Color object. Identical to dW\Pigmentum\Color::averageWithLab
.
colors
: One or more colors to average.
Example
Outputs:
dW\Pigmentum\Color::averageWithLab
Averages the provided colors in the L*a*b* color space and returns a new Color object. Identical to dW\Pigmentum\Color::average
.
colors
: One or more colors to average.
Example
Outputs:
dW\Pigmentum\Color::averageWithLCHab
Averages the provided colors in the LCH (L*a*b*) color space and returns a new Color object.
colors
: One or more colors to average.
Example
Outputs:
dW\Pigmentum\Color::averageWithRGB
Averages the provided colors in the RGB color space and returns a new Color object.
colors
: One or more colors to average.
Example
Outputs:
dW\Pigmentum\Color::averageWithHSB
Averages the provided colors in the HSB color space and returns a new Color object.
colors
: One or more colors to average.
Example
Outputs:
dW\Pigmentum\Color::mix
Mixes the color with a provided color in the L*a*b* color space and returns a new Color object. Identical to dW\Pigmentum\Color::mixWithLab
.
color
: Color to mix with$this
.percentage
: How strong to mix the color with$this
.
Example
Outputs:
dW\Pigmentum\Color::mixWithLab
Mixes the color with a provided color in the L*a*b* color space and returns a new Color object. Identical to dW\Pigmentum\Color::mix
.
color
: Color to mix with$this
.percentage
: How strong to mix the color with$this
.
Example
Outputs:
dW\Pigmentum\Color::mixWithLCHab
Mixes the color with a provided color in the LCH (L*a*b*) color space and returns a new Color object.
color
: Color to mix with$this
.percentage
: How strong to mix the color with$this
.
Example
Outputs:
dW\Pigmentum\Color::mixWithRGB
Mixes the color with a provided color in the RGB color space and returns a new Color object.
color
: Color to mix with$this
.percentage
: How strong to mix the color with$this
.
Example
Outputs:
dW\Pigmentum\Color::mixWithHSB
Mixes the color with a provided color in the HSB color space and returns a new Color object.
color
: Color to mix with$this
.percentage
: How strong to mix the color with$this
.
Example
Outputs:
dW\Pigmentum\Color::apcaContrast
Calculate the APCA (indented for use with the future WCAG 3) contrast between a text color ($this
) and a provided background color.
NOTE: This algorithm is in flux, and its results may change over time as the upstream reference algorithm is updated.
backgroundColor
: Color to calculate contrast against.
Example
Outputs:
dW\Pigmentum\Color::deltaE
Calculate the CIE2000 distance between $this
and a supplied color. Identical to dW\Pigmentum\Color::distance
.
color
: Color to calculate distance from.
Example
Outputs:
dW\Pigmentum\Color::distance
Calculate the CIE2000 distance between $this
and a supplied color. The CIE2000 distance formula takes perception into account when calculating. Identical to dW\Pigmentum\Color::deltaE
.
color
: Color to calculate distance from.
Example
Outputs:
dW\Pigmentum\Color::euclideanDistance
Calculate the geometric euclidean distance between $this
and a supplied color. This does not take perception into account when calculating. See dW\Pigmentum\Color::deltaE
for perceptual distance.
color
: Color to calculate distance from.
Example
Outputs:
dW\Pigmentum\Color::wcag2Contrast
Calculate the WCAG2 contrast between $this
and a provided color.
NOTE: While this is currently the standard for the Web it is not terribly accurate nor correct in its assessment. Use only if you're legally bound to do so. Even though the APCA contrast algorithm is in flux it already is much more accurate than the WCAG2 contrast ratio.
color
: Color to calculate contrast against.
Example
Outputs:
dW\Pigmentum\ColorSpace\Lab
Properties
- L (float): The Lightness channel for the color space.
- a (float): The a channel for the color space.
- b (float): The b channel for the color space.
dW\Pigmentum\ColorSpace\Lab::toLCHab
Returns the LCH (L*a*b*) color space for the color.
Example
Outputs:
dW\Pigmentum\ColorSpace\RGB
Properties
- R (float): The R channel for the color space
- G (float): The G channel for the color space
- B (float): The B channel for the color space
- unclampedR (float): If the color is out of the profile's gamut this will represent the unclamped R channel for the color space, otherwise same as R
- unclampedG (float): If the color is out of the profile's gamut this will represent the unclamped G channel for the color space, otherwise same as G
- unclampedB (float): If the color is out of the profile's gamut this will represent the unclamped B channel for the color space, otherwise same as B
- profile (string): A string representation of the class name of the color profile the channel values are in
- outOfGamut (bool): True if the color is out of the profile's gamut, false if not
dW\Pigmentum\ColorSpace\RGB::changeProfile
Converts the color's profile and returns a RGB color space using the supplied profile.
profile
: A string representation of the class name of the color profile the channel values are in, defaults to the current working space
Example
Outputs:
dW\Pigmentum\ColorSpace\RGB::toHex
Returns a RGB hex string for the color.
Example
Outputs:
dW\Pigmentum\ColorSpace\RGB::toHSB
Returns the HSB color space for the color.
Example
Outputs:
dW\Pigmentum\ColorSpace\XYZ
Properties
- X (float): The X channel for the color space.
- Y (float): The Y channel for the color space.
- Z (float): The Z channel for the color space.
dW\Pigmentum\ColorSpace\XYZ::toLMS
Returns the LMS color space for the color.
Example
Outputs:
dW\Pigmentum\ColorSpace\XYZ::chromaticAdaptation
Converts an XYZ color from one illuminant to another.
new
: The new illuminant to convert toold
: The old illuminant
Example
Outputs:
dW\Pigmentum\ColorSpace\Lab\LCHab
Properties
- L (float): The Lightness channel for the color space.
- C (float): The Chroma channel for the color space.
- H (float): The Hue channel for the color space.
dW\Pigmentum\ColorSpace\RGB\HSB
Properties
- H (float): The Hue channel for the color space.
- S (float): The Saturation channel for the color space.
- B (float): The Brightness channel for the color space.
dW\Pigmentum\ColorSpace\XYZ\LMS
Properties
- rho (float): The Rho (L) channel for the color space.
- gamma (float): The Gamma (M) channel for the color space.
- beta (float): The Beta (S) channel for the color space.
dW\Pigmentum\Profile\RGB
This is the base abstract color profile class. All RGB color profiles must inherit from this.
dW\Pigmentum\Profile\RGB\AdobeRGB1998
dW\Pigmentum\Profile\RGB\DisplayP3
dW\Pigmentum\Profile\RGB\ProPhoto
dW\Pigmentum\Profile\RGB\Simple_sRGB
dW\Pigmentum\Profile\RGB\sRGB
All versions of pigmentum with dependencies
ext-dom Version *
ext-zip Version *
ext-mbstring Version *