17/03
2017
PHP Color Utilities
This library provides utilities function to ease color manipulation, (*1)
Install package with composer, (*3)
composer require hugsbrugs/php-color
In your PHP code, load library, (*4)
require_once __DIR__ . '/../vendor/autoload.php'; use Hug\Color\Color as Color;
Test a color is hexadecimal, (*5)
Color:: is_hexa_color($color, $with_hash = true);
Examples, (*6)
var_dump(Color::is_hexa_color('#fff')); (bool)true var_dump(Color::is_hexa_color('#fff555')); (bool)true var_dump(Color::is_hexa_color('frfrfr', false)); (bool)false
Convert hexadecimal color to RGB, (*7)
Color:: hexa_to_rgb($hex, $return = 'array');
Examples, (*8)
var_dump(Color::hexa_to_rgb('#fff')); array(3) { 'R' => int(255) 'G' => int(255) 'B' => int(255) } var_dump(Color::hexa_to_rgb('#fff555')); array(3) { 'R' => int(255) 'G' => int(245) 'B' => int(85) } var_dump(Color::hexa_to_rgb('frfrfr', 'string')); (bool)false
composer exec phpunit
Hugo Maugey visit my website ;), (*9)