Is Light Color

Check if a hex color is light (good for determining text color).

Code

General
h = hex.delete('#')
r, g, b = h[0,2].to_i(16), h[2,2].to_i(16), h[4,2].to_i(16)
return (r * 0.299 + g * 0.587 + b * 0.114) > 186

Parameters

Hex color to check

Server

More Ruby Snippets