Created
May 23, 2017 13:24
-
-
Save murillomarigo/e3d74acfd53d48168b92620639c0be2a to your computer and use it in GitHub Desktop.
Retorna se a cor que contrasta melhor com a cor passada é preto ou branco
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calculaCorDoTexto (bgColor) { | |
var re = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i; | |
var rgb = re.exec(bgColor); | |
var r = parseInt(rgb[1], 16), | |
g = parseInt(rgb[2], 16), | |
b = parseInt(rgb[3], 16); | |
var yiq = ((r * 299) + (g * 587) + (b * 114)) / 1000; | |
return yiq >= 128 ? 'black' : 'white'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment