"함수 str2rgb()"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(다른 사용자 한 명의 중간 판 22개는 보이지 않습니다)
1번째 줄: 1번째 줄:
[[분류: String]]
[[분류: String]]
[[분류: Color]]
[[분류: Color]]
[[분류: Conversion]]
[[분류: 변환]]
;string to color
;str2rgb()
;string2rgb()
;string2color()
;StringToRGB()


==PHP==
==PHP==
[[category: PHP]]
[[category: PHP]]
<source lang='php'>
{{참고|PHP str2rgb()}}
function stringToRgb( $str ) {
<syntaxhighlight lang='php'>
   $code = dechex(crc32(md5($str)));
function str2rgb( $str, $salt='' ) {
  return '#'.substr(md5($str.$salt),0,6);
}
</syntaxhighlight>
<syntaxhighlight lang='php'>
function str2rgb( $str, $salt='' ) {
   $code = dechex(crc32(md5($str.$salt)));
   $r = hexdec(substr($code,0,2))/2+127;
   $r = hexdec(substr($code,0,2))/2+127;
   $g = hexdec(substr($code,2,2))/2+127;
   $g = hexdec(substr($code,2,2))/2+127;
   $b = hexdec(substr($code,4,2))/2+127;
   $b = hexdec(substr($code,4,2))/2+127;
   return dechex($r).dechex($g).dechex($b);
   return '#'.dechex($r).dechex($g).dechex($b);
}
}
</source>
</syntaxhighlight>
 
==Python==
[[분류: Python]]
{{참고|파이썬 str2rgb()}}
<syntaxhighlight lang='python'>
import hashlib
def str2rgb(s):
    return '#'+hashlib.md5(s.encode('utf-8')).hexdigest()[:6]
print( str2rgb('hello') ) # #5d4140
print( str2rgb('world') ) # #7d7930
</syntaxhighlight>
<syntaxhighlight lang='python'>
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
</syntaxhighlight>


==같이 보기==
==같이 보기==
*[[RGB]]
*[[RGB]]

2020년 11월 2일 (월) 02:33 기준 최신판

string to color
str2rgb()
string2rgb()
string2color()
StringToRGB()

1 PHP[ | ]

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);
}

2 Python[ | ]

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

3 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}