summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSergey Shliakhov <husband.sergey@gmail.com>2020-01-08 13:21:50 +0100
committerSergey Shliakhov <husband.sergey@gmail.com>2020-01-27 09:42:45 +0100
commitacc0df1d13a082e5531acf76047ff24c85230289 (patch)
tree43156444c5e8b39a569105ffc8fd0965bebee443 /lib
parentaa950ffc044e318ccd8885fe311f46e87277f517 (diff)
downloadnextcloud-server-acc0df1d13a082e5531acf76047ff24c85230289.tar.gz
nextcloud-server-acc0df1d13a082e5531acf76047ff24c85230289.zip
Change avatar placeholder from single letter to 2 letters
https://github.com/nextcloud/server/issues/18717 Signed-off-by: Sergey Shliakhov <husband.sergey@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Avatar/Avatar.php20
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/private/Avatar/Avatar.php b/lib/private/Avatar/Avatar.php
index b2232f2ff00..5a91a09b4bf 100644
--- a/lib/private/Avatar/Avatar.php
+++ b/lib/private/Avatar/Avatar.php
@@ -89,13 +89,15 @@ abstract class Avatar implements IAvatar {
*
* @return string
*/
- private function getAvatarLetter(): string {
+ private function getAvatarText(): string {
$displayName = $this->getDisplayName();
if (empty($displayName) === true) {
return '?';
- } else {
- return mb_strtoupper(mb_substr($displayName, 0, 1), 'UTF-8');
}
+ $firstTwoLetters = array_map(function ($namePart) {
+ return mb_strtoupper(mb_substr($namePart, 0, 1), 'UTF-8');
+ }, explode(' ', $displayName, 2));
+ return implode('', $firstTwoLetters);
}
/**
@@ -130,9 +132,9 @@ abstract class Avatar implements IAvatar {
$userDisplayName = $this->getDisplayName();
$bgRGB = $this->avatarBackgroundColor($userDisplayName);
$bgHEX = sprintf("%02x%02x%02x", $bgRGB->r, $bgRGB->g, $bgRGB->b);
- $letter = $this->getAvatarLetter();
- $toReplace = ['{size}', '{fill}', '{letter}'];
- return str_replace($toReplace, [$size, $bgHEX, $letter], $this->svgTemplate);
+ $text = $this->getAvatarText();
+ $toReplace = ['{size}', '{fill}', '{text}'];
+ return str_replace($toReplace, [$size, $bgHEX, $text], $this->svgTemplate);
}
/**
@@ -168,7 +170,7 @@ abstract class Avatar implements IAvatar {
* @return string
*/
protected function generateAvatar($userDisplayName, $size) {
- $letter = $this->getAvatarLetter();
+ $text = $this->getAvatarText();
$backgroundColor = $this->avatarBackgroundColor($userDisplayName);
$im = imagecreatetruecolor($size, $size);
@@ -185,10 +187,10 @@ abstract class Avatar implements IAvatar {
$fontSize = $size * 0.4;
list($x, $y) = $this->imageTTFCenter(
- $im, $letter, $font, (int)$fontSize
+ $im, $text, $font, (int)$fontSize
);
- imagettftext($im, $fontSize, 0, $x, $y, $white, $font, $letter);
+ imagettftext($im, $fontSize, 0, $x, $y, $white, $font, $text);
ob_start();
imagepng($im);