Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

Get color code from string

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');
 
PREVIOUS NEXT
Tagged: #Get #color #code #string
ADD COMMENT
Topic
Name
3+9 =