PHP code example of lukapeharda / tailwindcss-color-palette-generator

1. Go to this page and download the library: Download lukapeharda/tailwindcss-color-palette-generator 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/ */

    

lukapeharda / tailwindcss-color-palette-generator example snippets


use LukaPeharda\TailwindCssColorPaletteGenerator\Color;
use LukaPeharda\TailwindCssColorPaletteGenerator\PaletteGenerator;

// from hex
$baseColor = Color::fromHex('#ffff00');

// or from RGB
$baseColor = Color::fromRgb(255, 255, 0);

// or from HSL
$baseColor = Color::fromHsl(60, 100, 50); // or $baseColor = Color::fromHsl(0.6, 1, 0.5);

$paletteGenerator = new PaletteGenerator;
$paletteGenerator->setBaseColor($baseColor);
$palette = $paletteGenerator->getPalette();

$palette = [
    50 => Color,
    100 => Color,
    200 => Color,
    300 => Color,
    ...
];

foreach ($palette as $key => $color) {
    echo '--color-primary-' . $key . ': #' . $color->getHex() . ';';
}

$paletteGenerator->setBaseValue(400);

$paletteGenerator->setThresholdLightest(80); // or $paletteGenerator->setThresholdLightest(0.8);
$paletteGenerator->setThresholdDarkest(20); // or $paletteGenerator->setThresholdDarkest(0.2);

$paletteGenerator->setColorSteps([100, 200, 300, 400, 500, 600, 700]);