Skip to content

Instantly share code, notes, and snippets.

@thedustin
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thedustin/0333e22517888cd20d0f to your computer and use it in GitHub Desktop.
Save thedustin/0333e22517888cd20d0f to your computer and use it in GitHub Desktop.
Calculate the textcolor (Black or White) by background-color (YIQ-Contrast) [http://24ways.org/2010/calculating-color-contrast/]
<?php
$fYIQ = (($iRed * 299) + ($iGreen * 587) + ($iBlue * 114)) / 1000;
if($fYIQ >= 128){
echo 'Black textcolor.';
} else {
echo 'White textcolor.';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment