ericpugh/handy-colors

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

Get the human name of a color and other handy color utilties

1.1.0 2019-12-16 18:12 UTC

This package is auto-updated.

Last update: 2020-12-22 22:26:09 UTC


README

Some handy color utilities.

Install with composer:

composer require ericpugh/handy-colors
  • requires with PHP 7.3 or greater.

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 Handy\Utils\Colors\Color;
use Handy\Utils\Colors\ColorPicker;

$picker = new ColorPicker();
$total_num_colors = $picker->countColorPalette();
// An example hex color.
$example_hex = '#83F600';
$example_color = new Color($picker::fromHexToInt($example_hex));
// Finds the closest HEX color in the current palette.
$closest = $picker->closestColor($example_color);
// Finds the name "lawngreen".
$name = $picker->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;

?>