PHP code example of popphp / pop-color

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

    

popphp / pop-color example snippets


$rgb = Color::rgb(120, 60, 30, 0.5);
echo $rgb . PHP_EOL;

$hex = $rgb->toHex();
echo $hex . PHP_EOL;

$hsl = $hex->toHsl();
echo $hsl . PHP_EOL;

// Will print a string of space-separated values, common to the PDF color string format
$cmyk = $rgb->toCmyk();
echo $cmyk . PHP_EOL; 

$rgb = Color::rgb(120, 60, 30, 0.5);
echo $rgb->getR() . PHP_EOL;
echo $rgb->getG() . PHP_EOL;
echo $rgb->getB() . PHP_EOL;
echo $rgb->getA() . PHP_EOL;

$cmyk = Color::cmyk(60, 30, 20, 50);
echo $cmyk->getC() . PHP_EOL;
echo $cmyk->getM() . PHP_EOL;
echo $cmyk->getY() . PHP_EOL;
echo $cmyk->getK() . PHP_EOL;

$rgb = Color::parse('rgba(120, 60, 30, 0.5)');
echo $rgb->getR() . PHP_EOL;
echo $rgb->getG() . PHP_EOL;
echo $rgb->getB() . PHP_EOL;
echo $rgb->getA() . PHP_EOL;
echo $rgb . PHP_EOL;