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.
Download delights/color
More information about delights/color
Files in delights/color
Package color
Short Description A simple library to work and smartly generate colors in PHP
License MIT
Informations about the package color
PHP Color
Installation
Requires PHP 8.3+
You can install the package via composer:
Features
- Support HSLA (and HSL)&, HEX, RGBA (and RGB)
- Generate a color for a given seed (like a user email)
- Darken, lighten the color.
- Compute the luminance, lightness, darkness
- Check the contrast of two colors
TOC
- Generating nice looking colors
- Working with the HSLA object
- From RGB to HSLA
- From Hex to HSLA
- From CSS to HSLA
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])
- Alpha [100, 100] (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 Hsla
objects. Let us see how they work.
Working with the HSLA object.
You may be getting a color from somewhere which is not HSLA, you can convert them:
From RGB to HSLA
From Hex to HSLA
From scratch
You may convert your HSLA color back to hex, RGB, HSLA...
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.
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.