Text color for buttons and alerts is now dynamic. Closes #1020, #1021

This commit is contained in:
James Brooks
2015-10-08 17:02:17 +01:00
parent 22c39df73f
commit d3fcffce72
2 changed files with 63 additions and 36 deletions

View File

@@ -95,3 +95,23 @@ if (!function_exists('color_darken')) {
return $new_hex;
}
}
if (!function_exists('color_contrast')) {
/**
* Calculates colour contrast.
*
* https://24ways.org/2010/calculating-color-contrast/
*
* @param string $hexcolor
*
* @return string
*/
function color_contrast($hexcolor) {
$r = hexdec(substr($hexcolor, 0, 2));
$g = hexdec(substr($hexcolor, 2, 2));
$b = hexdec(substr($hexcolor, 4, 2));
$yiq = (($r * 100) + ($g * 400) + ($b * 114)) / 1000;
return ($yiq >= 128) ? 'black' : 'white';
}
}