My question is if there is any way from Python to convert an RGB or HEX color value to the corresponding text of the color.
Example: * # FFFFFF -> WHITE * or * RGB (255,255,255) -> WHITE *
My question is if there is any way from Python to convert an RGB or HEX color value to the corresponding text of the color.
Example: * # FFFFFF -> WHITE * or * RGB (255,255,255) -> WHITE *
You would need to create a lookup table for all the colors you need:
hexToText = {'#FFFFFF':'WHITE', '#FF0000':'RED', '#00FF00':'GREEN', '#0000FF':'BLUE'}
testHex = '#FF0000'
testHexColor = hexToText[testHex] # now has 'RED'
rgbToText = {(255,255,255):'WHITE', (255,0,0):'RED', (0,255,0):'GREEN', (0,0,255):'BLUE'}
testRgb = (0,255,0)
testRgbColor = rgbToText[testRgb] # now has 'GREEN'