Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Avatar/Avatar.php')
-rw-r--r--lib/private/Avatar/Avatar.php58
1 files changed, 12 insertions, 46 deletions
diff --git a/lib/private/Avatar/Avatar.php b/lib/private/Avatar/Avatar.php
index 188e7378aff..25099a4f139 100644
--- a/lib/private/Avatar/Avatar.php
+++ b/lib/private/Avatar/Avatar.php
@@ -37,7 +37,7 @@ declare(strict_types=1);
namespace OC\Avatar;
use Imagick;
-use OC\Color;
+use OCP\Color;
use OCP\Files\NotFoundException;
use OCP\IAvatar;
use Psr\Log\LoggerInterface;
@@ -114,7 +114,7 @@ abstract class Avatar implements IAvatar {
protected function getAvatarVector(int $size): string {
$userDisplayName = $this->getDisplayName();
$bgRGB = $this->avatarBackgroundColor($userDisplayName);
- $bgHEX = sprintf("%02x%02x%02x", $bgRGB->r, $bgRGB->g, $bgRGB->b);
+ $bgHEX = sprintf("%02x%02x%02x", $bgRGB->red(), $bgRGB->green(), $bgRGB->blue());
$text = $this->getAvatarText();
$toReplace = ['{size}', '{fill}', '{letter}'];
return str_replace($toReplace, [$size, $bgHEX, $text], $this->svgTemplate);
@@ -122,13 +122,10 @@ abstract class Avatar implements IAvatar {
/**
* Generate png avatar from svg with Imagick
- *
- * @param int $size
- * @return string|boolean
*/
- protected function generateAvatarFromSvg(int $size) {
+ protected function generateAvatarFromSvg(int $size): ?string {
if (!extension_loaded('imagick')) {
- return false;
+ return null;
}
try {
$font = __DIR__ . '/../../core/fonts/NotoSans-Regular.ttf';
@@ -139,10 +136,9 @@ abstract class Avatar implements IAvatar {
$avatar->setImageFormat('png');
$image = new \OCP\Image();
$image->loadFromData((string)$avatar);
- $data = $image->data();
- return $data === null ? false : $data;
+ return $image->data();
} catch (\Exception $e) {
- return false;
+ return null;
}
}
@@ -156,9 +152,9 @@ abstract class Avatar implements IAvatar {
$im = imagecreatetruecolor($size, $size);
$background = imagecolorallocate(
$im,
- $backgroundColor->r,
- $backgroundColor->g,
- $backgroundColor->b
+ $backgroundColor->red(),
+ $backgroundColor->green(),
+ $backgroundColor->blue()
);
$white = imagecolorallocate($im, 255, 255, 255);
imagefilledrectangle($im, 0, 0, $size, $size, $background);
@@ -215,36 +211,6 @@ abstract class Avatar implements IAvatar {
return [$x, $y];
}
- /**
- * Calculate steps between two Colors
- * @param int $steps start color
- * @param Color[] $ends end color
- * @return array{0: int, 1: int, 2: int} [r,g,b] steps for each color to go from $steps to $ends
- */
- private function stepCalc(int $steps, array $ends): array {
- $step = [];
- $step[0] = ($ends[1]->r - $ends[0]->r) / $steps;
- $step[1] = ($ends[1]->g - $ends[0]->g) / $steps;
- $step[2] = ($ends[1]->b - $ends[0]->b) / $steps;
- return $step;
- }
-
- /**
- * Mix two colors
- *
- * @return Color[]
- */
- private function mixPalette($steps, Color $color1, Color $color2) {
- $palette = [$color1];
- $step = $this->stepCalc($steps, [$color1, $color2]);
- for ($i = 1; $i < $steps; $i++) {
- $r = intval($color1->r + ($step[0] * $i));
- $g = intval($color1->g + ($step[1] * $i));
- $b = intval($color1->b + ($step[2] * $i));
- $palette[] = new Color($r, $g, $b);
- }
- return $palette;
- }
/**
* Convert a string to an integer evenly
@@ -292,9 +258,9 @@ abstract class Avatar implements IAvatar {
// 3 colors * 6 will result in 18 generated colors
$steps = 6;
- $palette1 = $this->mixPalette($steps, $red, $yellow);
- $palette2 = $this->mixPalette($steps, $yellow, $blue);
- $palette3 = $this->mixPalette($steps, $blue, $red);
+ $palette1 = Color::mixPalette($steps, $red, $yellow);
+ $palette2 = Color::mixPalette($steps, $yellow, $blue);
+ $palette3 = Color::mixPalette($steps, $blue, $red);
$finalPalette = array_merge($palette1, $palette2, $palette3);