Spudhead
04-14-2003, 05:28 PM
I'm sure this has been raised before, but:
Say I'm pulling out some text content from a database; the content has a hex colour value attached to it. If it's a light colour, I want it on a dark background. And vice versa.
I could just knock up a script that takes the hex value for the curent colour and makes another; by reversing it for example. (We're not necessarily dealing with websafe colours here :))
But I'd like, basically, for any colours that would show up best on black to be on black, and any colours that read best on white to be on white.
Can I somehow work out the "best colour to be on" from the hex? Like, if it's mainly letters, or if the 3 values for RGB are roughly similar? Am I just off in Spudworld again?
And is case you hadn't guessed, this is more of an exercise than a practical problem, so "add the background colour as a database field" is not a valid answer ;)
Say I'm pulling out some text content from a database; the content has a hex colour value attached to it. If it's a light colour, I want it on a dark background. And vice versa.
I could just knock up a script that takes the hex value for the curent colour and makes another; by reversing it for example. (We're not necessarily dealing with websafe colours here :))
But I'd like, basically, for any colours that would show up best on black to be on black, and any colours that read best on white to be on white.
Can I somehow work out the "best colour to be on" from the hex? Like, if it's mainly letters, or if the 3 values for RGB are roughly similar? Am I just off in Spudworld again?
And is case you hadn't guessed, this is more of an exercise than a practical problem, so "add the background colour as a database field" is not a valid answer ;)