📜  从字符串中获取颜色代码 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:26.032000             🧑  作者: Mango

代码示例1
function getColour($seed, $rgbArray = false) {
    $hash = md5($seed);
    $r = hexdec(substr($hash, 0, 2));
    $g = hexdec(substr($hash, 2, 2));
    $b = hexdec(substr($hash, 4, 2));
    if ($rgbArray) {
        return array('R' => $r, 'G' => $g, 'B' => $b);
    }
    $highR = $r + 10;
    $highG = $g + 10;
    $highB = $b + 10;
    $main = '#' . str_pad(dechex($r), 2, '0', STR_PAD_LEFT)
        . str_pad(dechex($g), 2, '0', STR_PAD_LEFT)
        . str_pad(dechex($b), 2, '0', STR_PAD_LEFT);
    $highlight = '#' . dechex($highR) . dechex($highG) . dechex($highB);
    return array('main' => $main, 'highlight' => $highlight);
}

$t = getColour('Assigned');