From 76d01653309f1535bfe8d364a5aae50e83a348e3 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Tue, 30 Aug 2022 13:58:51 +0200 Subject: Dark theme for guest avatar And better caching policy Signed-off-by: Carl Schwan --- lib/private/Avatar/Avatar.php | 2 +- lib/private/Avatar/GuestAvatar.php | 4 ++-- lib/private/Avatar/PlaceholderAvatar.php | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/private/Avatar/Avatar.php b/lib/private/Avatar/Avatar.php index aec0f6e10f4..1e6ebd7c61b 100644 --- a/lib/private/Avatar/Avatar.php +++ b/lib/private/Avatar/Avatar.php @@ -150,7 +150,7 @@ abstract class Avatar implements IAvatar { protected function generateAvatar(string $userDisplayName, int $size, bool $dark): string { $text = $this->getAvatarText(); $textColor = $this->avatarBackgroundColor($userDisplayName); - $backgroundColor = $textColor->alphaBlending(0.1, $dark ? new Color() : new Color(255, 255, 255)); + $backgroundColor = $textColor->alphaBlending(0.1, $dark ? new Color(0, 0, 0) : new Color(255, 255, 255)); $im = imagecreatetruecolor($size, $size); $background = imagecolorallocate( diff --git a/lib/private/Avatar/GuestAvatar.php b/lib/private/Avatar/GuestAvatar.php index 79d7e6ee094..083deb4108f 100644 --- a/lib/private/Avatar/GuestAvatar.php +++ b/lib/private/Avatar/GuestAvatar.php @@ -84,8 +84,8 @@ class GuestAvatar extends Avatar { /** * Generates an avatar for the guest. */ - public function getFile(int $size): ISimpleFile { - $avatar = $this->generateAvatar($this->userDisplayName, $size); + public function getFile(int $size, bool $darkTheme = false): ISimpleFile { + $avatar = $this->generateAvatar($this->userDisplayName, $size, $darkTheme); return new InMemoryFile('avatar.png', $avatar); } diff --git a/lib/private/Avatar/PlaceholderAvatar.php b/lib/private/Avatar/PlaceholderAvatar.php index 504e5c1457d..e7ca89f4d30 100644 --- a/lib/private/Avatar/PlaceholderAvatar.php +++ b/lib/private/Avatar/PlaceholderAvatar.php @@ -108,13 +108,13 @@ class PlaceholderAvatar extends Avatar { * @throws \OCP\Files\NotPermittedException * @throws \OCP\PreConditionNotMetException */ - public function getFile(int $size): ISimpleFile { + public function getFile(int $size, bool $darkTheme = false): ISimpleFile { $ext = 'png'; if ($size === -1) { - $path = 'avatar-placeholder.' . $ext; + $path = 'avatar-placeholder' . ($darkTheme ? '-dark' : '') . '.' . $ext; } else { - $path = 'avatar-placeholder.' . $size . '.' . $ext; + $path = 'avatar-placeholder' . ($darkTheme ? '-dark' : '') . '.' . $size . '.' . $ext; } try { @@ -124,8 +124,8 @@ class PlaceholderAvatar extends Avatar { throw new NotFoundException; } - if (!$data = $this->generateAvatarFromSvg($size)) { - $data = $this->generateAvatar($this->getDisplayName(), $size); + if (!$data = $this->generateAvatarFromSvg($size, $darkTheme)) { + $data = $this->generateAvatar($this->getDisplayName(), $size, $darkTheme); } try { -- cgit v1.2.3