PHPackages                             allenjb/initial-avatar-generator - 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. allenjb/initial-avatar-generator

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

allenjb/initial-avatar-generator
================================

A package to generate avatars with initials for PHP

0183↓100%PHP

Since Jan 4Pushed 3y agoCompare

[ Source](https://github.com/AllenJB/initial-avatar-generator)[ Packagist](https://packagist.org/packages/allenjb/initial-avatar-generator)[ RSS](/packages/allenjb-initial-avatar-generator/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Generate avatars with initials
==============================

[](#generate-avatars-with-initials)

Fork of [lasserafn/php-initial-avatar-generator](https://github.com/LasseRafn/php-initial-avatar-generator) updated to use [Imagine](https://github.com/php-imagine/Imagine), resolving issues with PHP 8.1

This library should be pretty much a drop-in replacement for most users with the following notable changes:

- This library uses strictly defined types
- This library returns Imagine objects instead for (non-SVG) generated avatars
- Font numbers in place of files were removed
- AutoFont functionality has been removed - you can reimplement this yourself using the lasserafn/php-string-script-language package
- Only the default Open Sans Regular font is shipped with the package
- FontAwesome files are no longer shipped with the library

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

[](#installation)

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

```
composer require allenjb/initial-avatar-generator
```

Usage
-----

[](#usage)

As with installation, usage is quite simple. Generating a image is done by running:

```
$avatar = new AllenJB\InitialAvatarGenerator\InitialAvatar();

$image = $avatar->name('Lasse Rafn')->generate();
```

Thats it! The method will return a instance of an [ImageInterface from Imagine](https://imagine.readthedocs.io/en/stable/_static/API/Imagine/Image/ImageInterface.html) so you can save or output the image:

```
return $image->show('png');
```

If only one word is passed, the first 2 letters will be used. If more than 2 words are passed, the initials of the first and last words will be used.

SVG generation
--------------

[](#svg-generation)

```
$avatar = new AllenJB\InitialAvatarGenerator\InitialAvatar();

echo $avatar->name('Lasse Rafn')->generateSvg()->toXMLString(); // returns SVG XML string
```

Supported methods and parameters
--------------------------------

[](#supported-methods-and-parameters)

### Name (initials) - default: JD

[](#name-initials---default-jd)

```
$image = $avatar->name('Albert Magnum')->generate();
```

### Width - default: 48

[](#width---default-48)

```
// will be 96 pixels wide.
$image = $avatar->width(96)->generate();
```

### Height - default: 48

[](#height---default-48)

```
// will be 96 pixels tall.
$image = $avatar->height(96)->generate();
```

### Size - default: 48 (proxy for `$avatar->width(X)->height(X)`)

[](#size---default-48-proxy-for-avatar-widthx-heightx)

```
// will be 96x96 pixels.
$image = $avatar->size(96)->generate();
```

### Background color - default: #f0e9e9

[](#background-color---default-f0e9e9)

```
// will be red
$image = $avatar->background('#ff0000')->generate();
```

### Font color - default: #8b5d5d

[](#font-color---default-8b5d5d)

```
// will be red
$image = $avatar->color('#ff0000')->generate();
```

### Font file - default: /fonts/OpenSans-Regular.ttf

[](#font-file---default-fontsopensans-regularttf)

```
// will be Semibold
$image = $avatar->font('/path/to/fonts/OpenSans-Semibold.ttf')->generate();
```

### Font name (for SVGs) - default: Open Sans, sans-serif

[](#font-name-for-svgs---default-open-sans-sans-serif)

```
$image = $avatar->fontName('Arial, Helvetica, sans-serif')->generate();
```

### Length - default: 2

[](#length---default-2)

```
$image = $avatar->name('John Doe Johnson')->length(3)->generate(); // 3 letters = JDJ
```

### Switching driver - default: gd

[](#switching-driver---default-gd)

```
$image = $avatar->gd()->generate(); // Uses GD driver
$image = $avatar->imagick()->generate(); // Uses Imagick driver
```

### Rounded - default: false

[](#rounded---default-false)

```
$image = $avatar->rounded()->generate();
```

### Smooth - default: false

[](#smooth---default-false)

Makes rounding smoother with a resizing hack. Could be slower.

```
$image = $avatar->rounded()->smooth()->generate();
```

Alternatively consider using CSS instead.

### Font Size - default: 0.5

[](#font-size---default-05)

```
$image = $avatar->fontSize(0.25)->generate(); // Font will be 25% of image size.
```

If the Image size is 50px and fontSize is 0.5, the font size will be 25px.

Chaining it all together
------------------------

[](#chaining-it-all-together)

```
return $avatar->name('Lasse Rafn')
              ->length(2)
              ->fontSize(0.5)
              ->size(96) // 48 * 2
              ->background('#8BC34A')
              ->color('#fff')
              ->generate()
              ->save('png');
```

Now, using that in a image (sized 48x48 pixels for retina):

```

```

Will yield:

[![Result](https://raw.githubusercontent.com/AllenJB/initial-avatar-generator/master/demo_result.png)](https://raw.githubusercontent.com/AllenJB/initial-avatar-generator/master/demo_result.png)

*Rounded for appearance; the actual avatar is a filled square*

Icon Font Support
-----------------

[](#icon-font-support)

First, you need to "find" the respective unicode for the glyph you want to insert. For example, using FontAwesome, to display a typical "user" icon use unicode: `f007`. You can usually find the unicode character (code) on the icon font browser.

An example for rendering a red avatar with a white "user" glyph would look like this:

```
// note that this code
// 1) uses glyph() instead of name
// 2) changes the font to FontAwesome!
return $avatar->glyph('f007')
              ->font('/path/to/fonts/FontAwesome5Free-Regular-400.otf')
              ->color('#fff')
              ->background('#ff0000')
              ->generate()
              ->save('png');
```

###  Health Score

17

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity23

Early-stage or recently created project

 Bus Factor1

Top contributor holds 89.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a89439e9dd92e45dffd3aa600f41346945bf2aefa46b047f8374b1dd44d3ef78?d=identicon)[AllenJB](/maintainers/AllenJB)

---

Top Contributors

[![LasseRafn](https://avatars.githubusercontent.com/u/2689341?v=4)](https://github.com/LasseRafn "LasseRafn (179 commits)")[![AllenJB](https://avatars.githubusercontent.com/u/5645829?v=4)](https://github.com/AllenJB "AllenJB (16 commits)")[![bcmcq](https://avatars.githubusercontent.com/u/4561584?v=4)](https://github.com/bcmcq "bcmcq (1 commits)")[![johannesschobel](https://avatars.githubusercontent.com/u/9431350?v=4)](https://github.com/johannesschobel "johannesschobel (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![psohm](https://avatars.githubusercontent.com/u/5886652?v=4)](https://github.com/psohm "psohm (1 commits)")

### Embed Badge

![Health badge](/badges/allenjb-initial-avatar-generator/health.svg)

```
[![Health](https://phpackages.com/badges/allenjb-initial-avatar-generator/health.svg)](https://phpackages.com/packages/allenjb-initial-avatar-generator)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
