1

If I look at the hex color code ff0000 I know its red. If I look at 43d94e I know its green. My question is, how do I figure out in php what color it is. According to microsoft, the main basic colors are:

Red
Pink
Orange
Yellow
Purple
Green
Blue
Brown
White
Grey

So how can I use php to figure out that ff0000 is red? Or 5400ff is purple. This way I will be able to group colors

Maggie
  • 61
  • 6
  • do you want to consider ever hex colour? or a limited set? do you want to be able to say `ff000a` is red? –  Dec 31 '18 at 05:10
  • @tim Yes, consider every hex color there is. And yes, if the input is `ff000a` it should just `echo "red"` – Maggie Dec 31 '18 at 05:11
  • Colour is the animals' perspective of the world, computers don't understand the concept of colour, but you can use PHP's associate array to map the value. –  Dec 31 '18 at 05:12
  • 3
    Convert RGB to HSV for simpler color approximation. Also, this isn't a PHP-specific question really. – mario Dec 31 '18 at 05:14
  • There a lot of colors. https://www.w3schools.com/colors/colors_crayola.asp What are you trying to accomplish overall? – blueseal Dec 31 '18 at 05:14
  • @catcon but I'm sure there is a way to determine if a color is `red`? I mean, hex are just numbers? Isn't there a formula that determines it? – Maggie Dec 31 '18 at 05:14
  • @blueseal Overall I am trying to group hex colors together (but not have 255 groups). Just Have 10 groups or 20 groups. Not a lot of them – Maggie Dec 31 '18 at 05:15
  • Have you decided on the group of colors? I'd square instead of taking the absolute values in the first answer for better accuracy. https://stackoverflow.com/questions/4126029/convert-rgb-values-to-color-name – blueseal Dec 31 '18 at 05:19
  • @blueseal yes. I have listed them in the first post – Maggie Dec 31 '18 at 05:20
  • I wasn't sure if you have decided since you said 10 or 20, but you should be good then. Just check out the different answers in the link and see if they work. – blueseal Dec 31 '18 at 05:22
  • @mario How would I convert hex to HSV? – Maggie Dec 31 '18 at 05:23
  • If you refresh the page, you should see some linked resources right above your question. But if you have more questions, feel free to ask! – blueseal Dec 31 '18 at 05:40

0 Answers0