Hello today, I will show you how to create avatars that are abbreviated as avatars in your Android phone book or Google account.
SETTING
To create avatars by initials we will need to install a package called laravolt / avatar. To install we perform the following:
If you are using Laravel> = 5.2
1 2 | composer require laravolt/avatar |
And if you are using the Laravel version <5.2:
1 2 | composer require laravolt/avatar ~0.3 |
CONFIG
Next we will implement the config according to our own, at this step we need a file to configure:
1 2 | php artisan vendor:publish --provider="LaravoltAvatarServiceProvider" |
After running the publish config command, you will have a file to configure in the following path config/laravolt/avatar.php
USE
To display as an image you just need to execute in the view file as follows:
1 2 | <img src="{{ Avatar::create($user->name)->toBase64() }}" /> |
In addition to creating the image as Base64, you can also use other methods to create images such as: toGravatar()
or toSvg()
Then come here when running the results, it will look like this:
As I said above we can customize the avatar.php
config file as we like, now I will try to reconfigure the image to be a square with a radius boder okay, in the avatar.php
file I will edit again the shape
is square
and radius
is 3
:
1 2 3 4 5 | 'shape' => 'square', 'border' => [ 'radius' => 3, ], |
After saving you do not forget to run
1 2 | php artisan config:cache |
Results after config:
CONCLUDE
Above is a tutorial on how we can create avatars are letters in the name of the name is also very simple, isn’t it.