W3Cで公開されているアルゴリズムを利用してみる。
0 1 2 3 4 5 6 7 8 9 10 11 |
// テーマのfunctions.php //背景色に対して文字色が黒か白か function black_or_white( $hexcolor ){ $r = intval(substr($hexcolor, 0,2),16); $g = intval(substr($hexcolor, 2,2),16); $b = intval(substr($hexcolor, 4,2),16); $c = ( ($r * 299) + ($g * 587) + ($b * 114) ) / 1000; $txtcolor= $c<128 ? "FFFFFF":"000000"; return $txtcolor; } |
例えば、
$txtcolor = black_or_white( d36015 );
とやると
$txtcolor は FFFFFF となるはず。