* #48 - postgreSQL db * #43 - vacation summary for employee (#66) * wip * wip * wip * wip * wip * wip * wip * #5 - bump dependencies * #43 - wip * #43 - add composer script * #43 - fix * #43 - fix * #43 - wip * #43 - ecs fix * #43 - cr fix * #43 - cr fix * #43 - fix Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl> * #48 - redis stuff * #48 - user avatars using ui-avatars.com * #48 - fix * #48 - fix * Apply suggestions from code review Co-authored-by: Marcin Tracz <marcin.tracz@blumilk.pl> * #48 - cr fix Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl> Co-authored-by: Marcin Tracz <marcin.tracz@blumilk.pl>
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Eloquent\Helpers;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use LasseRafn\InitialAvatarGenerator\InitialAvatar;
|
||||
use SVG\SVG;
|
||||
use Toby\Eloquent\Models\User;
|
||||
|
||||
class UserAvatarGenerator
|
||||
{
|
||||
public function __construct(
|
||||
protected InitialAvatar $generator,
|
||||
) {}
|
||||
|
||||
public function generateFor(User $user): string
|
||||
{
|
||||
$path = "avatars/{$this->generateUuid()}.svg";
|
||||
|
||||
Storage::put($path, $this->generate($user));
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
protected function generate(User $user): SVG
|
||||
{
|
||||
return $this->generator->rounded()
|
||||
->background($this->getColor($user->fullName))
|
||||
->color("#F4F8FD")
|
||||
->smooth()
|
||||
->fontSize(0.33)
|
||||
->generateSvg($user->fullName);
|
||||
}
|
||||
|
||||
protected function getColor(string $name): string
|
||||
{
|
||||
$colors = config("colors");
|
||||
|
||||
return $colors[strlen($name) % count($colors)];
|
||||
}
|
||||
|
||||
protected function generateUuid(): string
|
||||
{
|
||||
return Str::uuid()->toString();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user