PHP code example of mikealmond / color

1. Go to this page and download the library: Download mikealmond/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/ */

    

mikealmond / color example snippets


$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)
    );
}