src/includes/classes/Core/Utils/Color.php
public function contrastingBw(string $hex): string
    {
        $hex = $this->cleanHex($hex);

        $r = hexdec(substr($hex, 0, 2));
        $g = hexdec(substr($hex, 2, 2));
        $b = hexdec(substr($hex, 4, 2));

        $yiq = (($r * 299) + ($g * 587) + ($b * 114)) / 1000;

        return $yiq >= 128 ? '#000000' : '#ffffff';
    }
public function contrastingBw(string $hex): string
    {
        $hex = $this->cleanHex($hex);

        $r = hexdec(substr($hex, 0, 2));
        $g = hexdec(substr($hex, 2, 2));
        $b = hexdec(substr($hex, 4, 2));

        $yiq = (($r * 299) + ($g * 587) + ($b * 114)) / 1000;

        return $yiq >= 128 ? '#000000' : '#ffffff';
    }
Contrasting B/W color.

@since 161010 Color utilities.

@param string $hex Hex color code.

@return string Suggested B/W contrasting color.

@see https://24ways.org/2010/calculating-color-contrast/