PHP Classes

Avatar Generator: Generate an image for a person with a given name

Recommend this page to a friend!
  Info   View files Documentation   Screenshots Screenshots   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 281 This week: 1All time: 7,600 This week: 560Up
Version License PHP version Categories
zx-avatar-generator 1.1.2BSD License7.1Graphics, PHP 7
Description 

Author

This class can generate an image for a person with a given name.

It can take the name of a person and some additional options and generates an image that shows the person initial letters.

The color of the text, the background color and a background image are some of the possible options.

Innovation Award
PHP Programming Innovation award nominee
July 2018
Number 7
Many sites need to show images to represent the sites' users in an unique way.

Some create avatar images automatically based on the user personal name initials. This package implements a solution for that purpose.

Manuel Lemos
Picture of Egor Oldenburger
  Performance   Level  
Name: Egor Oldenburger is available for providing paid consulting. Contact Egor Oldenburger .
Classes: 1 package by
Country: Russian Federation Russian Federation
Age: ???
All time rank: 3883111 in Russian Federation Russian Federation
Week rank: 411 Up22 in Russian Federation Russian Federation Up
Innovation award
Innovation award
Nominee: 1x

Recommendations

Generate avatar from given name
I need to generate an avatar with the characters of a given name

Documentation

Avatar Generator

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

Latest Stable Version Total Downloads

Features

  • 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

Dependencies

  • PHP 7
  • PHP GD

Installation

Install with composer:

composer require zertex/avatar-generator

or add

"zertex/avatar-generator": "*"

to the require section of your composer.json file.

Configuration

$options = AvatarOptions::create()
			->setFont('path to ttf font')
			->setWidth(300)
			->setFontSize(200)
			->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

Using

Generate avatar image by username

$image_src = Avatar::init('John Smith', $options, [result file name])
			   ->username()
			   ->texture('TEXTURE_NAME')
			   ->text()
			   ->get_file_name();

Generate avatar image from file

$image_src = Avatar::init('John Smith', $options, [result file name])
			   ->file('/path/to/file')
			   ->texture('TEXTURE_NAME')
			   ->text()
			   ->get_file_name();

Generate avatar image from url

$image_src = Avatar::init('John Smith', $options, [result file name])
			   ->file('http://your-site.com/image.jpg')
			   ->texture('TEXTURE_NAME')
			   ->text()
			   ->get_file_name();

You can exclude texture or text from chain for exclude them

Textures

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`

Screenshot

alt text

Yii2 extension

Avater generator extension for Yii2 here: https://github.com/zertex/yii2-avatar-generator

Examples

https://zertex.ru/yii2-avatar-generator


Screenshots  
  • avatar-generator
  Files folder image Files  
File Role Description
Files folder imagesrc (2 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENCE.md Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file Avatar.php Class Class source
  Plain text file AvatarOptions.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 83%
Total:281
This week:1
All time:7,600
This week:560Up