I don’t suppose anyone knows of a function (PHP, preferably) that can take a hex color code and give an approximate color name for that hex value. I don’t need a solution with 100s of colors. Even if it just amounted to the colors white, black, red, green blue, brown orange and yellow, I’d be pretty well in shape.
If you don’t know of an existing resource, does anyone know of a good way to approach this problem?
Thanks in advance for the help.
You have a list of colors here in wikipedia.
A naive implementation would just calculate the distance between the color whose name you want to retrieve and every one of those and output the one that’s closer.
If you see the colors as vectors in R3, you could calculate the distance as L1 norm:
or the L2 norm:
For converting the hexadecimal notation, see here.
Example script: