Jump to content

[SOLVED] Hex code?


kernelgpf

Recommended Posts

try this

 

<?php 
$sire  = '#FFFFFF';
$dam =  '#018274';

$cub = avgColor($sire, $dam);


echo "<table border='1'>
    <tr>
        <th>Sire</th> 
        <th>Cub</th> 
        <th>Dam</th>
    </tr>
    <tr>
        <td style='color: $cub; background-color: $sire'>$sire</td>
        <td style='color: black; background-color: $cub'>$cub</td>
        <td style='color: $cub; background-color: $dam'>$dam</td>
    </tr>
    </table>
    ";
    
    
function rgb ($color)
{
    $color = hexdec(trim($color, '#'));
    $r = ($color >> 16) & 0xFF;
    $g = ($color >>  & 0xFF;
    $b = ($color)  & 0xFF;
    return array ($r, $g, $b);
}

function avgColor ($a, $b)
{
    $ar1 = rgb ($a);
    $ar2 = rgb ($b);
    $res = array();
    foreach ($ar1 as $k => $c1)
    {
        $c2 = $ar2[$k];
        $res[$k] = round(($c1 + $c2)/2);
    }
    
    return vsprintf ('#%02X%02X%02X', $res);
}

?>

Link to comment
https://forums.phpfreaks.com/topic/54501-solved-hex-code/#findComment-269601
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.