mikealmond / color
A small library to manipulate and display colors
Fund package maintenance!
mikealmond
Installs: 160 871
Dependents: 2
Suggesters: 0
Security: 0
Stars: 24
Watchers: 5
Forks: 3
Open Issues: 0
Requires (Dev)
- phpunit/phpunit: ~6.0|~7.0|~8.0|~9.0
- squizlabs/php_codesniffer: ^3.0
README
This library will allow you to alter colors, check readability, and generate different palettes based on a base color.
Install
Via Composer
$ composer require mikealmond/color
Usage
$color = Color::fromHex('FFFFFF'); echo $color->getRgb()['b']; // 255 /** @var Color $darkerColor */ $darkerColor = $color->darken(50); // 50% darker echo $darkerColor; // implements `__toString()` if ($darkerColor->isDark()) { // do something with a dark color }
// Create a color palette based on #663399 $color = Color::fromCssColor('RebeccaPurple'); $generator = new PaletteGenerator($color); $palette = $generator->triad(40); foreach ($palette as $color) { printf( '<div style="background-color:%s;color:%s;text-align:center;">%s</div>', CssGenerator::hex($color), CssGenerator::hex($color->getMatchingTextColor()), CssGenerator::rgb($color) ); }
Change log
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.