hugsbrugs/php-color

There is no license information available for the latest version (dev-master) of this package.

PHP Color Utilities

dev-master 2017-03-17 18:07 UTC

This package is auto-updated.

Last update: 2022-07-19 21:31:58 UTC


README

This library provides utilities function to ease color manipulation

Build Status Coverage Status

Install

Install package with composer

composer require hugsbrugs/php-color

In your PHP code, load library

require_once __DIR__ . '/../vendor/autoload.php';
use Hug\Color\Color as Color;

Test a color is hexadecimal

Color:: is_hexa_color($color, $with_hash = true);

Examples

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

Color:: hexa_to_rgb($hex, $return = 'array');

Examples

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

Unit Tests

composer exec phpunit

Author

Hugo Maugey visit my website ;)