News for hackers. Stuff that matters.
Re:Calculating Color Contrast for Legible Text in Ruby by azymm on Sunday July 18, 2010 @11:33PM (#1527520)
I also had to do something like this for my Python project and ended up with this:

'#000' if int(my_color, 16) > 0xffffff/2 else '#fff'

This approach isn't perfect, but it does the job.

Re:Calculating Color Contrast for Legible Text in Ruby by extension on Monday July 19, 2010 @05:25AM (#1528062)
No it doesn't. That effectively ignores the green and blue channels.
Re:Calculating Color Contrast for Legible Text in Ruby by azymm on Monday July 26, 2010 @04:15PM (#1549128)
Ah, thank you very much for pointing that out!
Re:Calculating Color Contrast for Legible Text in Ruby by xhuang on Monday July 19, 2010 @06:08AM (#1528131)
This is ugly, but it should do the job:

"#000000" if sum([int(i,16) for i in re.findall("..",myColour)]) > 382.5 else "#ffffff"