Core Coding®

PHP Visible Text

  PHP Visible Text
Make sure your text is always visible no matter what the background color.
function visibleText($color) {
  
$color trim($color);
  if (
$color[0] == '#') {
    
$color substr($color1);
    
$pound '#';
  }

  if (
strlen($color) == 3) {
    
$colors = array(hexdec($color[0] . $color[0]), hexdec($color[1] . $color[1]), hexdec($color[2] .
$color[2]));
  } elseif (
strlen($color) == 6) {
    
$colors = array(hexdec(substr($color02)), hexdec(substr($color22)), hexdec(substr($color42)));
  } else {
    return 
$pound $color;
  }

  if (
array_sum($colors) > 255 1.5) {
    return 
$pound '000';
  } else {
    return 
$pound 'FFF';
  };
};
Go back to resources
Home Mail GitHub