PHP code example of villfa / invert-color

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

    

villfa / invert-color example snippets



InvertColor\Color;
use InvertColor\Exceptions\InvalidColorFormatException;

try {
    echo Color::fromHex('#fff')->invert(); // #000000
} catch (InvalidColorFormatException $e) {
    echo 'Invalid color: ', $e->getValue();
}

InvertColor\Color::fromHex('#fff')->invert(); // #000000

InvertColor\Color::fromRGB([0, 255, 0])->invert(); // #ff00ff

InvertColor\Color::fromHex('#000')->invert(); // #ffffff
InvertColor\Color::fromHex('#282b35')->invert(); // #d7d4ca

// amplify to black or white
InvertColor\Color::fromHex('282b35')->invert(true); // #ffffff

InvertColor\Color::fromHex('#000')->invertAsRGB(); // [255, 255, 255]
InvertColor\Color::fromHex('#282b35')->invertAsRGB(); // [215, 212, 202]

// amplify to black or white
InvertColor\Color::fromHex('282b35')->invertAsRGB(true); // [255, 255, 255]

InvertColor\Color::fromHex('#000')->invertAsObj()->getHex(); // #ffffff
InvertColor\Color::fromHex('#282b35')->invertAsObj()->getRGB(); // [215, 212, 202]

// amplify to black or white
InvertColor\Color::fromHex('282b35')->invertAsObj(true)->getRGB(); // [255, 255, 255]


InvertColor\Color::fromHex('#FFF')->getHex(); // #ffffff

InvertColor\Color::fromHex('#fff')->getRGB(); // [255, 255, 255]

InvertColor\Color::fromHex('#fff')->getLuminance(); // 1
InvertColor\Color::fromHex('#000')->getLuminance(); // 0

InvertColor\Color::fromHex('#fff')->isBright(); // true
InvertColor\Color::fromHex('#000')->isBright(); // false

InvertColor\Color::fromHex('#fff')->isDark(); // false
InvertColor\Color::fromHex('#000')->isDark(); // true