1. Go to this page and download the library: Download awcode/awcolor library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
awcode / awcolor example snippets
use AWcode\awColor;
// Construct from any common format
$color = new awColor('#ff0000'); // hex (3, 4, 6 or 8 digits)
$color = awColor::fromString('rgb(255, 0, 0)'); // CSS rgb()/rgba()/hsl()/hsla()
$color = awColor::fromName('rebeccapurple'); // CSS3/CSS4 named color
$color = awColor::fromHsl(120, 1.0, 0.5); // HSL factory
$color = awColor::fromHsv(0, 1.0, 1.0); // HSV
$color = awColor::fromCmyk(0, 1, 1, 0); // CMYK
$color = awColor::random(); // Random opaque color
echo $color; // "#ff0000" (Stringable)
echo $color->getRgbaString(); // "rgba(255, 0, 0, 1)"
echo $color->getHslString(); // "hsl(0, 100%, 50%)"
print_r($color->getHsv()); // [0, 1.0, 1.0]
print_r($color->getCmyk()); // [0.0, 1.0, 1.0, 0.0]
$color->lighten(0.1); // +10% lightness
$color->darken(0.1);
$color->saturate(0.2);
$color->desaturate(0.2);
$color->rotate(60); // hue rotation in degrees
$color->invert();
$color->grayscale();
$color->mix($other, 0.5); // blend two colors
$color->tint(0.2); // mix toward white
$color->shade(0.2); // mix toward black
$color->fadeIn(0.1);
$color->fadeOut(0.1);
$fg = new awColor('#222');
$bg = new awColor('#fff');
$fg->luminance(); // WCAG 2.x relative luminance (0-1)
$fg->contrastRatio($bg); // 21.0 for max contrast
$fg->isAccessible($bg); // AA, normal text (>= 4.5)
$fg->isAccessible($bg, 'AAA'); // AAA, normal text (>= 7.0)
$fg->isAccessible($bg, 'AA', 'large'); // AA, large text (>= 3.0)
// Pick the best foreground for a given background
$bg->pickReadable(new awColor('#000'), new awColor('#fff'));