mikealmond/color

A small library to manipulate and display colors

Fund package maintenance!
mikealmond

v0.1.5 2021-10-08 17:16 UTC

This package is auto-updated.

Last update: 2024-12-09 00:43:06 UTC


README

Build Status Code Coverage Scrutinizer Code Quality

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.