PHP Classes


Recommend this page to a friend!
  Classes of Egor Oldenburger   Avatar Generator   Download  
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: Avatar Generator
Generate an image for a person with a given name
Author: By
Last change:
Date: 5 years ago
Size: 2,764 bytes


Class file image Download

Avatar Generator

Generate avatar for user by his name, file or url.

Latest Stable Version Total Downloads


  • Saving to PNG format
  • Generate avatar by username
  • Generate avatar from file or url (http only)
  • Auto select background color by username
  • Contrast color for text
  • Font face and size customize
  • PNG Textures for background


  • PHP 7
  • PHP GD


Install with composer:

composer require zertex/avatar-generator

or add

"zertex/avatar-generator": "*"

to the require section of your composer.json file.


$options = AvatarOptions::create()
			->setFont('path to ttf font')
			->setTexturesFolder('path to textures folder')
			->setImagesFolder('path to generated images folder')
			->setImagesUrl('url to images folder')
			->setSalt('random salt');

  • setFont - Path to TTF font
  • setWidth - Width & height avatar image file. Default: 300
  • setFontSize - Font size. Default: 200
  • setTexturesFolder - Path to textures folder. Used only PNG textures
  • setImagesFolder - Path to image folder.
  • setImagesUrl - Url for generating complete link to image
  • setSalt - Random text for new image file name


Generate avatar image by username

$image_src = Avatar::init('John Smith', $options, [result file name])

Generate avatar image from file

$image_src = Avatar::init('John Smith', $options, [result file name])

Generate avatar image from url

$image_src = Avatar::init('John Smith', $options, [result file name])

You can exclude texture or text from chain for exclude them


You can use PNG texture with transparancy. Every texture must consist of 2 files (back & white). His names myst be:

TEXTURE_NAME . '-' . COLOR . '.png'
  • TEXTURE_NAME - Any words. In texture() method you can use array of TEXTURE_NAME for random
  • COLOR - Must be `black` or `white`


alt text

Yii2 extension

Avater generator extension for Yii2 here: