diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-05-07 10:50:33 +0200 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-06-13 18:46:04 +0200 |
commit | ed4309ce41557d39576108731631ac59aa6e3120 (patch) | |
tree | 808111ff8e0e0f579273d2a266db5a1b24788d78 /lib | |
parent | eea6f74ca47e94f6b740dbd33d10e22faf4221a5 (diff) | |
download | nextcloud-server-ed4309ce41557d39576108731631ac59aa6e3120.tar.gz nextcloud-server-ed4309ce41557d39576108731631ac59aa6e3120.zip |
Unify colour algorithm output
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Avatar.php | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/private/Avatar.php b/lib/private/Avatar.php index 6858346f22b..0ea2b82f5ea 100644 --- a/lib/private/Avatar.php +++ b/lib/private/Avatar.php @@ -408,14 +408,20 @@ class Avatar implements IAvatar { } /** - * @param string $text + * @param string $hash * @return Color Object containting r g b int in the range [0, 255] */ - public function avatarBackgroundColor(string $text) { - $hash = preg_replace('/[^0-9a-f]+/', '', $text); + public function avatarBackgroundColor(string $hash) { + // Normalize hash + $hash = strtolower($hash); + + // Already a md5 hash? + if( preg_match('/^([0-9a-f]{4}-?){8}$/', $hash, $matches) !== 1 ) { + $hash = md5($hash); + } - $hash = md5($hash); - $hashChars = str_split($hash); + // Remove unwanted char + $hash = preg_replace('/[^0-9a-f]+/', '', $hash); $red = new Color(182, 70, 157); $yellow = new Color(221, 203, 85); |