giordanocardillo

Contrast YIQ

Nov 17th, 2020 (edited)
325
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getContrastYIQ(hexcolor){
  2.   const r = parseInt(hexcolor.substr(0,2), 16)
  3.   const g = parseInt(hexcolor.substr(2,2), 16)
  4.   const b = parseInt(hexcolor.substr(4,2), 16)
  5.   const yiq = ((r * 299) + (g * 587) + (b * 114)) / 1000
  6.   return (yiq >= 128) ? 'black' : 'white'
  7. }
RAW Paste Data