Find a color's hexadecimal value from its name.
This library does not only list all the HTML colors, but also :
- Australian Independent Colour Standard (AS 2700)
- Some major brands color (Google, Netflix, Facebook, etc)
- Federal Standard 595 colors
- ISCC–NBS system colors
- Natural Color System colors
- RAL colour standard colors
- Resene colors
- X11 colors
- and some other colors (Crayola colors, food colors, and even XKCD's colors from its 2010 survey)
With composer :
composer require brio/named-colors
use Brio\NamedColors;
// Find a color from its name or reference
// Note that, if multiple matches are possible, the first match is returned
// html colors are always first to be matched
$color = NamedColors::findHexByName('red'); // returns #FF0000
$color = NamedColors::findHexByName('Google Red'); // returns #EA4335
// Find a color from its name, with a specific color set
$color = NamedColors::findHexByName('red', 'xkcd'); // returns #E50000
Feel free to add your own color schemes, as soon as they meet these requirements :
- All colors schemes should be created in the
src/colors
directory - They must only contain one array, named
$colors
- Each item of this array must have one key, and these three values :
- reference
- name
- hexa
- The key should be a camelCase version of the color's name
reference
andname
are not mandatory- The
hexa
key is mandatory, it should contain the hexadecimal value of the color, prefixed with a sharp (#
).
The first release's colors all come from the W3Schools website, thanks to them !