Download the PHP package delights/color without Composer
On this page you can find all versions of the php package delights/color. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package color
PHP Color
Installation
Requires PHP 8.3+
You can install the package via composer:
Features
- Support HSL, HEX, RGB
- Generate a color for a given seed (like a user email)
- Darken, lighten the color.
- Check the lightness, darkness
- Check the contrast of two colors
- Parse colors from CSS
TOC
- Generating nice looking colors
- Working with the HSL object
- From RGB to HSL
- From Hex to HSL
- From CSS to HSL
Usage
Generating nice looking colors
You can generate colors on the fly:
Important: the colors generated are generate with the following defaults
- Hue: [0, 360] (all hues)
- Saturation: [50, 90] (out of [0, 100])
- Lightness [50, 70] (out of [0, 100])
This generates bright, saturated colors.
You may change the defaults for all generated colors used by the Generator
.
Or some of the defaults
You may force the generator to use a certain seed:
This also works for Generator::many
and Generator::manyLazily
.
You may override the default hue, saturation, and lightness ranges used to generate a color:
Or specify a single number instead of a range:
The generator returns Hsl
objects. Let us see how they work.
Working with the HSL object.
You may be getting a color from somewhere which is not HSL, you can convert them:
From RGB to HSL
From Hex to HSL
From CSS to HSL
This function silently ignores the transparent counterpart of the HSL, hex, and RGB format.
From scratch
You may convert your HSL color back to hex, RGB, HSL...
You may access the properties of the color:
And check the brightness of a color:
You may also specify a threshold, a number between 0 (darkest) and 100 (brightest):
You may darken or lighten a given color:
Luminance
As in https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef. This is how bright, or how dark the color is. Instead of simply taking the average of the R, G, and B channel. This uses a formula that weights the R, G, B channels differently to produce a more accurate luminance value.
Contrast
As in https://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef. Very useful for accessibility testing. Returns a value between 1 and 21. Usually, this is written as 1:1 or 21:1. This returns "n:1".
Testing
PHP Color was created by Félix Dorn under the MIT license.