1
我正在使用以下函數來生成柔和的顏色。但有時會產生深色陰影(如#B69C97)。我如何確保只生成淺色調?如何根據字符串生成淡淡的淡色?
function get_color($name) {
$hash = md5($name);
$color1 = hexdec(substr($hash, 8, 2));
$color2 = hexdec(substr($hash, 4, 2));
$color3 = hexdec(substr($hash, 0, 2));
if($color1 < 128) $color1 += 128;
if($color2 < 128) $color2 += 128;
if($color3 < 128) $color3 += 128;
return "#" . dechex($color1) . dechex($color2) . dechex($color3);
}
你試過我的回答嗎?它有幫助嗎? –