PHP code example of tecnickcom / tc-lib-color

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

    

tecnickcom / tc-lib-color example snippets




= new \Com\Tecnick\Color\Web();
$rgb = $web->getRgbObjFromHex('#336699');

echo $rgb->getCssColor();      // rgb(51,102,153)
echo $rgb->getRgbHexColor();   // #336699
echo $rgb->getPdfColor();      // "0.200000 0.400000 0.600000 rg\n"

$web->getColorObj('rgb(51 102 153)');
$web->getColorObj('hsl(210,50%,40%)');
$web->getColorObj('cmyk(67%,33%,0%,40%)');
$web->getColorObj('lab(41% -2 -25)');
$web->getColorObj('steelblue');

use Com\Tecnick\Color\ColorModelType;
use Com\Tecnick\Color\Model;

$cmyk = Model::create(ColorModelType::Cmyk, [
    'cyan' => 0.67,
    'magenta' => 0.33,
    'yellow' => 0.0,
    'key' => 0.4,
    'alpha' => 1.0,
]);

$web = new \Com\Tecnick\Color\Web();

$web->getClosestWebColorFromString('#9577a6');          // 'lightslategray'
$web->getClosestWebColorByDeltaEFromString('#9577a6');  // 'plum'

$pdf = new \Com\Tecnick\Color\Pdf();

$pdf->getPdfFillColor('steelblue');       // "0.274510 0.509804 0.705882 rg\n"
$pdf->addSpotColorFromArray('My Spot', ['cyan' => 1]);
$pon = 0;
$objects = $pdf->getPdfSpotObjects($pon); // write these first
$resources = $pdf->getPdfSpotResources(); // then reference them