PHPackages                             renfordt/larvatar - 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. [Image &amp; Media](/categories/media)
4. /
5. renfordt/larvatar

ActiveLibrary[Image &amp; Media](/categories/media)

renfordt/larvatar
=================

A PHP package to provide you with many variants of avatars.

v2.0.2(1y ago)44.3k↓16.7%[2 PRs](https://github.com/renfordt/larvatar/pulls)MITPHPPHP ^8.2CI passing

Since Jan 25Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/renfordt/larvatar)[ Packagist](https://packagist.org/packages/renfordt/larvatar)[ RSS](/packages/renfordt-larvatar/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (16)Used By (0)

Larvatar
========

[](#larvatar)

[![Badge](https://camo.githubusercontent.com/fac96bfab8afad81d9d5b1f8385fac9a921021586cd4f319deed833df5caa8dd/687474703a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d72656e666f7264742f4c617276617461722d626c75652e737667)](https://github.com/renfordt/Larvatar)[![Packagist Version](https://camo.githubusercontent.com/e2a001b7bd2ca3c2fcb7281d2593970b2284dfc0769fb2db24febd84f92cc140/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72656e666f7264742f6c617276617461723f696e636c7564655f70726572656c6561736573)](https://packagist.org/packages/renfordt/larvatar/)[![Packagist PHP Version](https://camo.githubusercontent.com/c29ff56e0835d5a3f392fb46d333721dcab43f57bb895f3b7e70deea9f8881d2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f72656e666f7264742f6c617276617461722f706870)](https://camo.githubusercontent.com/c29ff56e0835d5a3f392fb46d333721dcab43f57bb895f3b7e70deea9f8881d2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f72656e666f7264742f6c617276617461722f706870)[![GitHub License](https://camo.githubusercontent.com/9f5f2804ca1b91ddc9721355e3e2e272f4513e51ffacb5d856424d74d0b528e5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f72656e666f7264742f4c61727661746172)](https://camo.githubusercontent.com/9f5f2804ca1b91ddc9721355e3e2e272f4513e51ffacb5d856424d74d0b528e5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f72656e666f7264742f4c61727661746172)[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/5933e693f048c1a5448814d9e6b7dc7b08fa51cc43b0bbb4ded8e587ef301fba/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f72656e666f7264742f4c617276617461722f746573742e796d6c3f6c6f676f3d676974687562)](https://camo.githubusercontent.com/5933e693f048c1a5448814d9e6b7dc7b08fa51cc43b0bbb4ded8e587ef301fba/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f72656e666f7264742f4c617276617461722f746573742e796d6c3f6c6f676f3d676974687562)[![Code Coverage](https://camo.githubusercontent.com/6b06d5bad600d9466f2987a691391d4be8f3ee4dda3f40494bc12e6f630b7c74/68747470733a2f2f716c74792e73682f67682f72656e666f7264742f70726f6a656374732f6c617276617461722f636f7665726167652e737667)](https://qlty.sh/gh/renfordt/projects/larvatar)[![Maintainability](https://camo.githubusercontent.com/0f02cd52402496285c368f00f2796967499242e1a1b4826675dc5dbb1792ba44/68747470733a2f2f716c74792e73682f67682f72656e666f7264742f70726f6a656374732f6c617276617461722f6d61696e7461696e6162696c6974792e737667)](https://qlty.sh/gh/renfordt/projects/larvatar)

Larvatar is a package that combines different avatar styles, like Gravatar, Initials Avatar.

[![Avatar Types](avatars.png)](avatars.png)

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

[](#installation)

The recommended way of installing Larvatar is to use [Composer](https://getcomposer.org/). Run the following command to install it to you project:

```
composer require renfordt/larvatar

```

Upgrading to 2.0
----------------

[](#upgrading-to-20)

Version 2.0 brings many breaking changes. Check the [Upgrade Guide](UPGRADING.md) to avoid any issues.

Basic Usage
-----------

[](#basic-usage)

Include the LarvatarTrait with `use Renfordt\Larvatar\Traits\LarvatarTrait;` in your user class and add the following method:

```
    /**
     * Generate and retrieve the avatar URL or HTML for the user.
     *
     * @param int $size The size of the avatar in pixels.
     * @param bool $encoding Whether to return the encoded image as HTML.
     * @return string The avatar as a string URL or encoded HTML.
     */
    public function getAvatar(int $size = 100, bool $encoding = true): string
    {
        $larvatar = $this->getLarvatar($this->name, $this->email);
        $larvatar->setSize($size);
        $larvatar->setWeight('600');
        return $larvatar->getImageHTML(true);
    }
```

Adjust the method as you please, only requirement is that the methods name is `getAvatar()`.

Advanced Usage
--------------

[](#advanced-usage)

The general usage is simple. Create a new Larvatar class, insert name and email and the avatar type you wish.

```
