<?php
$hexa = '#add555';
$r = hexdec(substr($hexa,1,2)); // Se for sem o #, mude para 0, 2 $g = hexdec(substr($hexa,3,2)); // Se for sem o #, mude para 3, 2 $b = hexdec(substr($hexa,5,2)); // Se for sem o #, mude para 5, 2 $luminosidade = ( $r * 299 + $g * 587 + $b * 114) / 1000;
echo 'R: ' . $r . PHP_EOL;
echo 'G: ' . $g . PHP_EOL;
echo 'B: ' . $b . PHP_EOL;
echo 'Luminosidade: ' . $luminosidade . PHP_EOL;
if( $luminosidade > 128 ) {
echo 'Cor clara';
} else {
echo 'Cor escura';
}
PD9waHAKCgkkaGV4YSA9ICcjYWRkNTU1JzsKCSRyID0gaGV4ZGVjKHN1YnN0cigkaGV4YSwxLDIpKTsgLy8gU2UgZm9yIHNlbSBvICMsIG11ZGUgcGFyYSAwLCAyCgkkZyA9IGhleGRlYyhzdWJzdHIoJGhleGEsMywyKSk7IC8vIFNlIGZvciBzZW0gbyAjLCBtdWRlIHBhcmEgMywgMgoJJGIgPSBoZXhkZWMoc3Vic3RyKCRoZXhhLDUsMikpOyAvLyBTZSBmb3Igc2VtIG8gIywgbXVkZSBwYXJhIDUsIDIKCSRsdW1pbm9zaWRhZGUgPSAoICRyICogMjk5ICsgJGcgKiA1ODcgKyAkYiAqIDExNCkgLyAxMDAwOwoJCgllY2hvICdSOiAnIC4gJHIgLiBQSFBfRU9MOwoJZWNobyAnRzogJyAuICRnIC4gUEhQX0VPTDsKCWVjaG8gJ0I6ICcgLiAkYiAuIFBIUF9FT0w7CgllY2hvICdMdW1pbm9zaWRhZGU6ICcgLiAkbHVtaW5vc2lkYWRlIC4gUEhQX0VPTDsKCQoJaWYoICRsdW1pbm9zaWRhZGUgPiAxMjggKSB7CgkJZWNobyAnQ29yIGNsYXJhJzsKCX0gZWxzZSB7CgkJZWNobyAnQ29yIGVzY3VyYSc7Cgl9Cg==