ericpugh/dub-color

This package is abandoned and no longer maintained. The author suggests using the americanart/studio package instead.

Get the human name of a color.

1.0.0 2017-01-07 17:22 UTC

This package is not auto-updated.

Last update: 2022-01-18 17:04:43 UTC


README

Find the english language name of a (HEX) color. Names provided by one of the following color palettes, or can be extended to use a custom palette:

Example Usage

<?php

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;

?>