Skip to main content

Find the brightness of HEX color

function get_brightness($hex) {
// returns brightness value from 0 to 255

// strip off any leading #
$hex = str_replace('#', '', $hex);

$c_r = hexdec(substr($hex, 0, 2));
$c_g = hexdec(substr($hex, 2, 2));
$c_b = hexdec(substr($hex, 4, 2));

return (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
}

It will return the brightness.
if ($this->get_brightness($msg_color) > 130){$text_color='black';}
                    else {$text_color='white';}

Popular posts from this blog

The old company comeup with new brand MAXBEN - Logo meaning

I am so happy to design this logo for my friend Suresh Mahalingam to boost his paint business to the next level. The first step in his process is logo design. He had a clear idea about his business, processes, pricing and target audience. I just collect all those information from him and created the logo with some appropriate meanings. Check out the logo here