Converting RGB, HEX or HSL to primary color names
===

I have a long list of RGB, HEX and HSL codes for each of my 500,000 photos. Is there an algorithm/conversion out there that could convert RGB/HEX/HSL codes (whichever) to primary color names like red, green, yellow, blue, pink, black. I don't want names like Air Force Blue or Poo Brown, I just want all blues in blue, all reds in red and so on.

I thought this was easy when dealing with HSL codes because all blues are between 180-250 (hue), and I started to do that. I then realised that if you reduce the saturation and lightness you get a green color, so I stopped and thought, "I wonder if there's something already written for this somewhere". So here I ask.... 



