PHP code example of decodelabs / spectrum

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

    

decodelabs / spectrum example snippets


use DecodeLabs\Spectrum\Color;

$color = Color::create('#5AB3CD');
$color = Color::create('darkblue');
$color = Color::create('rgba(25,25,25,0.4)');
$color = Color::random();

$color->toHsl();
$color->lighten(0.3); // 30% lighter
$color->setAlpha(0.5); // 50% opacity
$color->toMidtone(); // Medium saturation and lightness

echo $color; // Converts to appropriate CSS value

$contrastColor = $color->contrastAgainst('pink');
$textColor = $color->getTextContrastColor();