Last active
December 22, 2023 11:11
-
-
Save boilemmashem/77f50d4e66124393a882f74294ffc778 to your computer and use it in GitHub Desktop.
Black/White maximum contrast detection
This file contains 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
/** | |
* Return black or white, whichever has higher contrast given the input color. | |
* | |
* @param {string} n - Input hexcolor without # | |
* @return {string} – white or black hex value with # | |
* | |
* @example | |
* | |
* getMaxContrast('FFFFFF') // #000000 | |
*/ | |
function getMaxContrast(hexcolor){ | |
return (parseInt(hexcolor, 16) > 0xffffff/2) ? '#000000':'#FFFFFF'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment