- string to color
- str2rgb()
- string2rgb()
- string2color()
- StringToRGB()
1 PHP[ | ]

PHP
Copy
function str2rgb( $str, $salt='' ) {
return '#'.substr(md5($str.$salt),0,6);
}
PHP
Copy
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);
}
2 Python[ | ]

Python
Copy
import hashlib
def str2rgb(s):
return '#'+hashlib.md5(s.encode('utf-8')).hexdigest()[:6]
print( str2rgb('hello') ) # #5d4140
print( str2rgb('world') ) # #7d7930
Python
Copy
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
3 같이 보기[ | ]
로그인하시면 댓글을 쓸 수 있습니다.
- 분류 댓글:
- Python (25)
- PHP (8)
리눅스 Python 2.7 컴파일 설치 ― …리눅스 Python 2.7 컴파일 설치 ― …리눅스 Python 2.7 컴파일 설치 ― …리눅스 Python 2.7 컴파일 설치 ― …리눅스 Python 2.7 컴파일 설치 ― Jmnote리눅스 Python 2.7 컴파일 설치 ― ㅇㅇㅇ미운코딩새끼 ― 승호 도령미운코딩새끼 ― 불탄고등어미운코딩새끼 ― 김레이미운코딩새끼 ― 호박이미운코딩새끼 ― Junhg0211미운코딩새끼 ― 김왼손미운코딩새끼 ― 용딘이미운코딩새끼 ―Pinkcrimson
유기농냠냠파이썬 ― 호박유기농냠냠파이썬 ― 이에스유기농냠냠파이썬 ― 이승현파이썬 global ― Jmnote파이썬 global ― John Jeong파이썬 global ― Jmnote파이썬 global ― John Jeong파이썬 global ― John Jeong파이썬 global ― John Jeong파이썬 global ― Jmnote파이썬 global ― John Jeong