Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Official Laravel wrapper for

Build Status Coverage Total Downloads Latest Stable Version License


You just require using composer and you're good to go!

composer require rackbeat/laravel-ui-avatars

The Service Provider is automatically registered.


To setup the config file, you publish it like so:

php artisan vendor:publish --provider="Rackbeat\UIAvatars\UIAvatarsServiceProvider"

You can edit the file in config/ui-avatars.php.


1. Add the Rackbeat\UIAvatars\HasAvatar trait to your Model (e.g. App\Users)

// ...
class User extends Authenticatable {
  use \Rackbeat\UIAvatars\HasAvatar;
  // ...

2. Create a new method on your Model.

This method is practically a proxy to call the HasAvatar methods. It will return a gravatar from the e-mail, with a fallback to the avatar using API.

public function getAvatar( $size = 64 ) {
  return $this->getGravatar( $this->email, $size );

NOTICE: Gravatar is only available using the API, not locally generated avatars.

3. (Optional) Re-define the name field

Assuming you're not using the default User Model in Laravel, you can override which field is being used for the name.

public function getAvatarNameKey( ) {
  return 'full_name';

Available methods


Returns the generated initials, from the name, used in the avatar.

Default $length can be defined in config/ui-avatars.php (length key)


Return a urlfriendly formatted avatar (URL or base64).

Example usage:

<img src="{{ $user->getUrlfriendlyAvatar() }}" />

Default $size can be defined in config/ui-avatars.php (image_size key)


Return a base64 representation of the avatar.

Default $size can be defined in config/ui-avatars.php (image_size key)


Return a Image object of the avatar.

Default $size can be defined in config/ui-avatars.php (image_size key)

getGravatar($email, $size=null)

Return a link to a Gravatar image using the specified email, and a fallback to using our own generator (assuming provider = api)

Default $size can be defined in config/ui-avatars.php (image_size key)

Available options

In the config file you can specify different options.

Key Description Default Available Options / Type
provider Which provider to use for generating avatars. api local or api
length Max initials length (amount of letters) 2 Number, min: 1, max: unlimited
image_size Default width & height for the generated avatar. 48 Number, min: 1, max: unlimited (512 using api provider)
font_size Font size in percentage of image_size. 0.5 Number, min: 0, max: 1
rounded Should the generated avatar be a rounded circle? (its recommended to disable and round using CSS) false Boolean
smooth_rounding If rounded is enabled, and provider is local, you can enable smoother rounding with the cost of performance. true Boolean
uppercase Should the initials be forced uppercase or not. true Boolean
background_color Default HEX background color for avatars. #a0a0a0 Hex
font_color Default HEX font color for avatars. #222 Hex
providers List of available providers. For you to add your own provider. Array of providers


  • PHP >= 7.1


Official Laravel wrapper.







No packages published

Contributors 4