Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

avatar

> 后端框架
Open source

Plug n play avatar, turn name, email, and any other string into beautiful avatar (or gravatar), effortless.

2.0K stars0 likes1 views
WebsiteGitHub

About

Plug n play avatar, turn name, email, and any other string into beautiful avatar (or gravatar), effortless.

laravolt/avatar

Display unique avatar for any user based on their (initials) name.

Preview

:film_strip: Video Tutorial

Requirements

Version PHP Laravel Intervention Image
7.x >= 8.3 10.x – 13.x ^4.0
6.x >= 8.1 10.x – 12.x ^3.0
5.x >= 8.0 9.x – 11.x ^2.0

Installation

This package was originally built for Laravel, but can also be used in any PHP project.

Read more about integration with PHP project here.

bash
composer require laravolt/avatar

The service provider and Avatar facade are registered automatically via package auto-discovery.

Publish Config (optional)

php
php artisan vendor:publish --provider="Laravolt\Avatar\ServiceProvider"

This will create config file located in config/laravolt/avatar.php.

Lumen Service Provider

php
$app->register(Laravolt\Avatar\LumenServiceProvider);

Usage

Output as base64

php
//this will output data-uri (base64 image data)
//something like data:image/png;base64,iVBORw0KGg....
Avatar::create('Joko Widodo')->toBase64();

//use in view
//this will display initials JW as an image
toBase64() }}" />

Save as file

php
Avatar::create('Susilo Bambang Yudhoyono')->save('sample.png');
Avatar::create('Susilo Bambang Yudhoyono')->save('sample.jpg', 100); // quality = 100

Output as Gravatar

php
Avatar::create('[email protected]')->toGravatar();
// Output: http://gravatar.com/avatar/0c5cbf5a8762d91d930795a6107b2ce5814a6ab26e60c7ec6b75bc81c7dfe3ee

Avatar::create('[email protected]')->toGravatar(['d' => 'identicon', 'r' => 'pg', 's' => 100]);
// Output: http://gravatar.com/avatar/0c5cbf5a8762d91d930795a6107b2ce5814a6ab26e60c7ec6b75bc81c7dfe3ee?d=identicon&r=pg&s=100

Gravatar parameter reference: https://docs.gravatar.com/api/avatars/images/

Output as SVG

php
Avatar::create('Susilo Bambang Yudhoyono')->toSvg();

You may specify custom font-family for your SVG text.

xml
<head>
    
    <link href="https://fonts.googleapis.com/css?family=Laravolt" rel="stylesheet">

    

    
    <style>
    @font-face {
        font-family: Laravolt;
        src: url({{ asset('fonts/laravolt.woff')) }});
    }
    </style>
</head>
php
Avatar::create('Susilo Bambang Yudhoyono')->setFontFamily('Laravolt')->toSvg();

You may make the SVG responsive. This excludes the height and width attributes.

php
Avatar::create('Susilo Bambang Yudhoyono')->setResponsive()->toSvg();

Get underlying Intervention image object

php
Avatar::create('Abdul Somad')->getImageObject();

The method will return an instance of Intervention image object, so you can use it for further purposes.

Non-ASCII Character

By default, this package will try to output any initials letter as it is. If the name supplied contains any non-ASCII character (e.g. ā, Ě, ǽ) then the result will depend on which font used (see config). If the font supports the characters supplied, they will be displayed successfully, otherwise they will not.

Alternatively, we can convert all non-ascii to their closest ASCII counterparts. If no closest counterparts are found, those characters are removed. Thanks to Stringy for providing such useful functions. What we need is just change one line in config/avatar.php:

php
    'ascii'    => true,

Configuration

…

Overriding config at runtime

We can override configuration at runtime by using the following functions:

…

Integration with other PHP project

php
// include composer autoload
require 'vendor/autoload.php';

// import the Avatar class
use Laravolt\Avatar\Avatar;

// create your first avatar
$avatar = new Avatar($config);
$avatar->create('John Doe')->toBase64();
$avatar->create('John Doe')->save('path/to/file.png', $quality = 90);

$config is just an ordinary array with same format as explained above (See Configuration).

Support Us

Buy Me A Coffee

Donate Via PayPal

Traktir Saya

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHPavatargravatarlaravel-packagephp

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category后端框架
PricingOpen source

> Related tools

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架