The `laravolt/avatar` package is a plug-and-play solution for generating avatars from names, emails, or any other strings in Laravel. Here are the key points about this package:
Installation and Setup
1. Installation: You can install the package using Composer:bash
composer require laravolt/avatar
2. Service Provider: Add the service provider to your `config/app.php` file:
php
'providers' => [
// ...,
Laravolt\Avatar\ServiceProvider::class,
],
3. Facade: Add the facade to your `config/app.php` file:
php
'aliases' => [
'Avatar' => Laravolt\Avatar\Facade::class,
],
Usage
1. Basic Usage: Generate an avatar from a string:php
<img src="{{ Avatar::create('Joko Widodo')->toBase64() }}" />
2. Customization: You can customize the avatar generation by setting various parameters:
php
Avatar::create('Soekarno')->setDimension(100, 200);
Avatar::create('Soekarno')->setBackground('#001122');
Avatar::create('Soekarno')->setShape('square');
Configuration
1. Configuration File: You can publish the configuration file using:bash
php artisan vendor:publish --provider="Laravolt\Avatar\ServiceProvider"
2. Configuration Options: The configuration file allows you to set various options such as the image driver, font, and colors:
php
<?php
return [
// Supported: "gd", "imagick"
'driver' => 'gd',
// Initial generator class
'generator' => \Laravolt\Avatar\Generator\DefaultGenerator::class,
// Whether all characters supplied must be replaced with their closest ASCII counterparts
'ascii' => false,
// Image shape: circle or square
'shape' => 'circle',
// Image width, in pixel
'width' => 100,
// Image height, in pixel
'height' => 100,
// Number of characters used as initials
'chars' => 2,
// Font size
'fontSize' => 48,
// Convert initial letter to uppercase
'uppercase' => false,
// Fonts used to render text
'fonts' => ['path/to/OpenSans-Bold.ttf', 'path/to/rockwell.ttf'],
// List of foreground colors to be used
'foregrounds' => ['#FFFFFF'],
// List of background colors to be used
'backgrounds' => [
'#f44336',
'#E91E63',
'#9C27B0',
'#673AB7',
'#3F51B5',
'#2196F3',
'#03A9F4',
'#00BCD4',
'#009688',
'#4CAF50',
'#8BC34A',
'#CDDC39',
'#FFC107',
'#FF9800',
'#FF5722',
],
'border' => [
'size' => 1,
'color' => 'foreground',
],
];
Additional Features
1. SVG Output: You can generate SVG avatars:php
{!! Avatar::create('Susilo Bambang Yudhoyono')->toSvg() !!}
2. Non-ASCII Characters: The package supports non-ASCII characters by default. You can also convert them to their closest ASCII counterparts if needed:
php
'ascii' => true,
Compatibility
1. Laravel Versions: The package supports Laravel versions 5.2 and above.2. PHP Versions: It supports PHP versions 7.2 and above.
Example Tutorial
1. Laravel 9 Avatar Generation Example: A step-by-step tutorial on how to implement avatar generation in Laravel 9 using the `laravolt/avatar` package.Issues and Support
1. GitHub Issues: The package has an active issue tracker on GitHub, where users can report bugs and request features.2. Stack Overflow: There are also questions and answers on Stack Overflow related to using this package with Auth0 and other Laravel versions.
Overall, `laravolt/avatar` is a robust and widely used package for generating avatars in Laravel applications, providing a simple and customizable way to manage avatar generation.
Citations:[1] https://laravel-news.com/laravolt-avatar
[2] https://www.youtube.com/watch?v=z8MDcHWXGwQ
[3] https://github.com/laravolt/avatar
[4] https://github.com/laravolt/avatar/releases
[5] https://laracasts.com/discuss/channels/laravel/avatar-generator