PHP code example of philiprehberger / php-color
1. Go to this page and download the library: Download philiprehberger/php-color 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/ */
philiprehberger / php-color example snippets
use PhilipRehberger\Color\Color;
$color = Color::hex('#ff6347'); // From hex
$color = Color::rgb(255, 99, 71); // From RGB
$color = Color::hsl(9, 100, 64); // From HSL
$color = Color::named('tomato'); // From CSS name
$color = Color::random(); // Random color
$color = Color::hex('#ff6347');
$color->toHex(); // '#ff6347'
$color->toRgb(); // 'rgb(255, 99, 71)'
$color->toHsl(); // 'hsl(9, 100%, 63.9%)'
$color->toArray(); // ['r' => 255, 'g' => 99, 'b' => 71, 'alpha' => 1.0]
$color = Color::hex('#3366cc');
$color->lighten(20); // Lighten by 20%
$color->darken(10); // Darken by 10%
$color->saturate(15); // Increase saturation by 15%
$color->desaturate(15); // Decrease saturation by 15%
$color->invert(); // Invert the color
$color->grayscale(); // Convert to grayscale
$red = Color::hex('#ff0000');
$blue = Color::hex('#0000ff');
$red->mix($blue, 0.5); // Mix two colors
$red = Color::hex('#ff0000');
$blue = Color::hex('#0000ff');
$red->blend($blue, 'multiply'); // Multiply blend
$red->blend($blue, 'screen'); // Screen blend
$red->blend($blue, 'overlay'); // Overlay blend
$red->blend($blue, 'darken'); // Darken blend
$red->blend($blue, 'lighten'); // Lighten blend
$color = Color::hex('#3366cc');
$color->isLight(); // false
$color->isDark(); // true
$red = Color::hex('#ff0000');
$blue = Color::hex('#0000ff');
$red->distance($blue); // CIE76 Delta E perceptual distance
$text = Color::hex('#333333');
$bg = Color::hex('#ffffff');
$text->contrastRatio($bg); // 12.63
$text->meetsWcagAA($bg); // true (>= 4.5:1)
$text->meetsWcagAAA($bg); // true (>= 7:1)
// Also accepts hex strings directly
$text->contrastRatio('#ffffff');
use PhilipRehberger\Color\Palette;
$color = Color::hex('#ff6347');
Palette::complementary($color); // [original, complement]
Palette::analogous($color); // [left, original, right]
Palette::triadic($color); // [original, +120deg, +240deg]
Palette::splitComplementary($color); // [original, +150deg, +210deg]
Palette::tetradic($color); // [original, +90deg, +180deg, +270deg]
Palette::shades($color, 5); // 5 progressively darker shades
Palette::tints($color, 5); // 5 progressively lighter tints
$black = Color::hex('#000000');
$white = Color::hex('#ffffff');
Palette::gradient($black, $white, 5); // 5-step RGB gradient
Palette::gradient($black, $white, 5, 'hsl'); // 5-step HSL gradient
bash
composer