2016-12-21 26 views
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); 
} 
+0

你試過我的回答嗎?它有幫助嗎? –

回答

0

#B69C97是在RGB中的(182,156,151)。根據你的代碼你的「黑暗」定義小於128,這被證明是錯誤的,因爲(182, 156, 151)對你來說仍然是「黑暗的」。我會嘗試將這個默認的「黑色」值從128更改爲更高的值,比如說160.就這個例子而言,您將消除包含小於160的值的顏色,如同您的情況,並減少平均輸出。