Download the PHP package popphp/pop-color without Composer
On this page you can find all versions of the php package popphp/pop-color. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download popphp/pop-color
More information about popphp/pop-color
Files in popphp/pop-color
Package pop-color
Short Description Pop Color Component for Pop PHP Framework
License BSD-3-Clause
Homepage https://github.com/popphp/pop-color
Informations about the package pop-color
pop-color
- Overview
- Install
- Quickstart
- Create a color object
- Convert to another color format
- Hex colors with alpha
- HSV, HSB, and HWB
- Lab, Lch, Oklab, and Oklch
- Accessing Color Properties
- Parse Color Strings
- Error Handling
Overview
Pop Color is a helpful component to manage different types of color values and conversions. Supported color formats include:
- RGB
- HEX
- HSL
- HSV
- HSB
- HWB
- CMYK
- Grayscale
- LAB
- LCH
- OKLAB
- OKLCH
Within the Pop PHP Framework, the pop-css, pop-image and pop-pdf components use this component.
Top
Install
Install pop-color using Composer.
composer require popphp/pop-color
Or, require it in your composer.json file
"require": {
"popphp/pop-color" : "^2.0.0"
}
Top
Quickstart
Create a color object
The above command will print the default CSS format:
Convert to another color format
Not every color's default string format is CSS — Cmyk and Grayscale default to the PDF-style format above, and
Hsv/Hsb (below) default to a delegated rgb(...)/rgba(...) string rather than anything HSV-shaped. Call
toCss() when you need guaranteed CSS output regardless of which color class you're holding:
Hex colors with alpha
Hex accepts (and round-trips) the 4-digit #RGBA and 8-digit #RRGGBBAA CSS hex-with-alpha formats, alongside
the standard 3- and 6-digit forms. Alpha is exposed as the same 0-1 float used by Rgb/Hsl:
HSV, HSB, and HWB
Hsv and Hsb are the same color model (hue/saturation/value, or hue/saturation/brightness) exposed as two
separate classes with the third channel named differently:
Hwb is a native CSS Color 4 format, so — unlike Hsv/Hsb — its default string output is real hwb(...)
syntax, with a /-alpha suffix when alpha is set:
Lab, Lch, Oklab, and Oklch
Lab, Lch, Oklab, and Oklch are native CSS Color 4 formats (like Hwb), so their default string output is
real lab(...)/lch(...)/oklab(...)/oklch(...) syntax. Unlike every other class in this library, alpha on
these four is getAlpha()/setAlpha()/hasAlpha(), not getA()/setA() — Lab and Oklab already use a
for their own axis channel, so alpha needed a different name to avoid colliding with it:
Lch and Oklab construct and convert the same way:
Color::parse() also recognizes lab(...), lch(...), oklab(...), and oklch(...) strings:
Accessing Color Properties
Every channel is also readable (and settable) via ArrayAccess or magic property access, as an alternative to
the getter/setter methods:
toArray() returns every channel (including alpha, when set) as a plain array:
Parse Color Strings
Color::parse() also recognizes hsv(...), hsb(...), and hwb(...) strings. hwb(...) accepts both the
legacy comma-separated form and native CSS Color 4 space-separated syntax with a /-alpha suffix:
Color::parse() also sniffs #hex strings, space-separated CMYK strings, and bare numeric grayscale strings —
it dispatches on the shape of the string rather than requiring a format hint:
Error Handling
Color::parse() throws Pop\Color\Color\Exception for any string it doesn't recognize, and every setter throws
OutOfRangeException for a value outside its valid range:
Top