blog.craiga.id.auConverting a color to grayscale

I’ve looked for this formula, on average, once a year for the past five or so years. It’s useful for determining what colour text to display over a colour: if y > 0.5, display white; otherwise, display black.

Hopefully by posting it here, I’ll be able to find it a bit easier next time.

// y = luminance
// r, g and b = the red, green and blue components of
// a colour
y = 0.3r + 0.59g + 0.11b

Published: Monday, 27th October 2008 at 11:22 PM

Related

About Craig Anderson

By day, he works for ABC TV as a web dev­el­oper. By night, he plays bass gui­tar in Look Who's Tox­ic. He also runs a little Unix Time­stamp con­ver­sion site. There are plen­ty of other things he should be doing, but most of the time he's dreaming of what he'll do when he grows up while watching bad Star Trek spin-offs.