PHP code example of oceanmoon / color
1. Go to this page and download the library: Download oceanmoon/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/ */
oceanmoon / color example snippets
use OceanMoon\Color\Color;
// Create colors from various formats
$red = new Color('red');
$orange = new Color('#ff8000');
$purple = Color::fromRgba(128, 0, 255);
$green = Color::fromHsla(120, 1.0, 0.5);
// Access color properties
$color = new Color('#ff8040');
$color->red; // 255
$color->hue; // 20.0
$color->lightness; // 0.625
// Modify colors (returns new instance)
$darkRed = $red->withLightness(0.3);
$transparent = $red->withAlpha(128);
// Color operations
$mixed = $red->mix($blue, 0.5);
$complement = $red->complement();
// Accessibility
$textColor = $background->bestTextColor(); // 'black' or 'white'
$ratio = $color1->contrastRatio($color2);
// Output formats
echo $color->toHex(); // '#ff8040ff'
echo $color->toRgbString(); // 'rgb(255 128 64 / 1)'
echo $color->toHslString(); // 'hsl(20deg 100% 62.5% / 1)'