PHP code example of ericpugh / dub-color
1. Go to this page and download the library: Download ericpugh/dub-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/ */
ericpugh / dub-color example snippets
use ericpugh\DubColor\Palette\Css4;
use ericpugh\DubColor\ColorDubber;
use ericpugh\DubColor\Color;
// Create instance of DubColor and set color palette to use.
$palette = Css4::getColors();
$dubber = new ColorDubber($palette);
$total_num_colors = $dubber->countColorPalette();
// An example hex color.
$example_hex = '#83F600';
$example_color = new Color($dubber::fromHexToInt($example_hex));
// Finds the closest HEX color in the current palette.
$closest = $dubber->closestColor($example_color);
// Finds the name "lawngreen".
$name = $dubber->getColorName($closest);
// Output results.
$label = sprintf('<span>Found 1 in %d colors</span>', $total_num_colors);
$color_span = sprintf('<span style="background-color:%s">Name: %s</span>', $closest, $name);
echo $label . $color_span;