PHPackages                             laravolt/avatar - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. laravolt/avatar

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

laravolt/avatar
===============

Turn name, email, and any other string into initial-based avatar or gravatar.

6.4.0(2mo ago)2.0k5.4M—3.2%182[1 issues](https://github.com/laravolt/avatar/issues)20MITPHPPHP &gt;=8.2CI passing

Since Oct 12Pushed 2mo ago34 watchersCompare

[ Source](https://github.com/laravolt/avatar)[ Packagist](https://packagist.org/packages/laravolt/avatar)[ Docs](https://github.com/laravolt/avatar)[ Fund](https://paypal.me/bayuhendra)[ Fund](https://ko-fi.com/bayuhendra)[ RSS](/packages/laravolt-avatar/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (18)Versions (67)Used By (20)

laravolt/avatar
===============

[](#laravoltavatar)

[![Total Downloads](https://camo.githubusercontent.com/1baa0404ce97b311c8543558cdabb8689c64533db8b681b08eef66f5e9b0e43c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c617261766f6c742f6176617461722e7376673f7374796c653d666c6174)](https://packagist.org/packages/laravolt/avatar)[![Monthly Downloads](https://camo.githubusercontent.com/27ab0f74ec5d54facdc89ed09a3c7b3df99b950c6ecc24b68bb923de2e4b46e6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6c617261766f6c742f6176617461722e7376673f7374796c653d666c6174)](https://packagist.org/packages/laravolt/avatar)[![Daily Downloads](https://camo.githubusercontent.com/2419b724d819c9f01e91fe3da1ada849a91b5bace05952a64d7b2e7169b3b3b9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64642f6c617261766f6c742f6176617461722e7376673f7374796c653d666c6174)](https://packagist.org/packages/laravolt/avatar)[![Run Tests](https://github.com/laravolt/avatar/workflows/run-tests/badge.svg)](https://github.com/laravolt/avatar/workflows/run-tests/badge.svg)

[![Preview](https://user-images.githubusercontent.com/149716/29503524-840ccd0c-8662-11e7-92f9-9ec3ed8a24af.png)](https://user-images.githubusercontent.com/149716/29503524-840ccd0c-8662-11e7-92f9-9ec3ed8a24af.png)

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

Preview
-------

[](#preview)

[![Preview](https://cloud.githubusercontent.com/assets/149716/26735022/6dbd77e2-47ea-11e7-8a05-7772465309c5.png)](https://cloud.githubusercontent.com/assets/149716/26735022/6dbd77e2-47ea-11e7-8a05-7772465309c5.png)

🎞️ Video Tutorial
-----------------

[](#film_strip-video-tutorial)

[![](https://camo.githubusercontent.com/add9cc14101277cc0fdd5cf5ea285697d3b51d3bed8f4a81cf2d4f6019032684/68747470733a2f2f696d672e796f75747562652e636f6d2f76692f6a44307775383863356b772f302e6a7067)](https://youtu.be/jD0wu88c5kw)

Installation
------------

[](#installation)

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

[Read more about integration with PHP project here.](#integration-with-other-php-project)

### Laravel &gt;= 5.2:

[](#laravel--52)

```
composer require laravolt/avatar
```

### Laravel 5.1:

[](#laravel-51)

```
composer require laravolt/avatar ~0.3
```

Service Provider &amp; Facade
-----------------------------

[](#service-provider--facade)

**Note: only for Laravel 5.4 and below, because since Laravel 5.5 we use package auto-discovery.**

```
Laravolt\Avatar\ServiceProvider::class,

...

'Avatar'    => Laravolt\Avatar\Facade::class,
```

Publish Config (optional)
-------------------------

[](#publish-config-optional)

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

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

Lumen Service Provider
----------------------

[](#lumen-service-provider)

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

Usage
-----

[](#usage)

### Output as base64

[](#output-as-base64)

```
//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

```

### Save as file

[](#save-as-file)

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

### Output as Gravatar

[](#output-as-gravatar)

```
Avatar::create('uyab@example.net')->toGravatar();
// Output: http://gravatar.com/avatar/0c5cbf5a8762d91d930795a6107b2ce5814a6ab26e60c7ec6b75bc81c7dfe3ee

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

Gravatar parameter reference:

### Output as SVG

[](#output-as-svg)

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

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

```

    @font-face {
        font-family: Laravolt;
        src: url({{ asset('fonts/laravolt.woff')) }});
    }

```

```
Avatar::create('Susilo Bambang Yudhoyono')->setFontFamily('Laravolt')->toSvg();
```

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

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

Get underlying Intervention image object
----------------------------------------

[](#get-underlying-intervention-image-object)

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

The method will return an instance of [Intervention image object](http://image.intervention.io/), so you can use it for further purposes.

Non-ASCII Character
-------------------

[](#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). It the font supports characters supplied, it will successfully displayed, otherwise it will not.

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

```
    'ascii'    => true,
```

Configuration
-------------

[](#configuration)

```
