PHP code example of phpexperts / color-speaker

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

    

phpexperts / color-speaker example snippets


$rgbSpeaker = ColorSpeaker::fromRGB(123, 111, 55);
$hexSpeaker = ColorSpeaker::fromHexCode('#7B6F37');
$hslSpeaker = ColorSpeaker::fromHSL(49, 38, 35);

$csv = ".box { background-color: $rgbSpeaker; }";
// .box { background-color: rgb(123, 111, 55); }
$csvHex = ".box { background-color: $hexSpeaker; }";
// .box { background-color: #7B6F37; }

$rgbColor = $rgbSpeaker->toRGB();
/*
   (string) $rgbColor === rgb(123, 111, 55);

   SimpleDTO => {
       'red'   => 123,
       'green' => 111,
       'blue'  => 55
   };
*/

$hexColor = $rgbSpeaker->toHexCode();
/**
    (string) $hexColor === #7B6F37

    SimpleDTO => {
        'hex' => '#7B6F37
    }
**/

$linguist = ColorSpeaker::fromHexCode('#7B6F37');
$rgbColor = $linguist->toRGB();
echo json_encode($rgbColor, JSON_PRETTY_PRINT);
/**
{
    "red": 123,
    "green": 111,
    "blue": 55
}
**/