function str2rgb( $str, $salt='' ) {
return '#'.substr(md5($str.$salt),0,6);
}
function str2rgb( $str, $salt='' ) {
$code = dechex(crc32(md5($str.$salt)));
$r = hexdec(substr($code,0,2))/2+127;
$g = hexdec(substr($code,2,2))/2+127;
$b = hexdec(substr($code,4,2))/2+127;
return '#'.dechex($r).dechex($g).dechex($b);
}
import hashlib
def str2rgb(s):
return '#'+hashlib.md5(s.encode('utf-8')).hexdigest()[:6]
print( str2rgb('hello') ) # #5d4140
print( str2rgb('world') ) # #7d7930
def str2rgb(s):
code = hashlib.md5(s.encode('utf-8')).hexdigest()
r = hex(int(code[0:2],base=16)//2+127)[2:]
g = hex(int(code[2:4],base=16)//2+127)[2:]
b = hex(int(code[4:6],base=16)//2+127)[2:]
return '#'+r+g+b