skrip42 / avatar-bundle
Symfony avatar bundle
Installs: 18
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^7.1
- skrip42/color: ^1.0
- symfony/config: ^4.2|^5.0
- symfony/dependency-injection: ^4.1|^5.0
- symfony/http-kernel: ^4.3|^5.0
- twig/twig: ^2.12|^3.0
This package is auto-updated.
Last update: 2024-10-18 18:32:21 UTC
README
avatar generator for symfony
install:
- run
composer require skrip42/avatar-bundle
base usage:
implement Skrip42\Bundle\AvatarBundle\UserInterface in you User Class:
.... use Symfony\Component\Security\Core\User\UserInterface; use Skrip42\Bundle\AvatarBundle\UserInterface as AvataredUserInterface; class User implements UserInterface, AvataredUserInterface { public function getUsername() : string { ... } public function getLastName() : ?string { ... } public function getFirstName() : ?string { ... } public function getPatronymicName() : ?string { ... } public function getAvatar() : ?string { ... } ..... }
call skrip42_avatar(user) function in twig template:
.... {{ skrip42_avatar(app.user) }} ....
configuration:
create config/packages/avatar.yaml file
avatar: color_generator: saturation: 0.9 #saturation of generated avatar lightness: 0.7 #lightness of generated avatar algo: 'fnv132' #hash alogorithm for avatar generation
customization:
customize base templates
{# create new file: templates/bundles/AvatarBundle/avatar.html.twig#} {% block avatar %} ... <img src = "{% block avatar_src %}{% endblock %}" ... "> ... {% endblock %}
customize generated avatar templates
{# create new file: templates/bundles/AvatarBundle/generatedAvatar.svg.twig#} ...... {# use 'color' and 'label' variable to generate avatar image #}
custom avatar generation
create custom avatar generator
namespace App\Utils; use Skrip42\Bundle\AvatarBundle\AvatarGeneratorInterface; use Skrip42\Bundle\AvatarBundle\UserInterface; class AvatarGenerator implements AvatarGeneratorInterface { public function getAvatar(UserInterface $user) : string { .... } }
and redeclare AvatarGenerator class
Skrip42\Bundle\AvatarBundle\AvatarGeneratorInterface: 'App\Utils\AvatarGenerator'