Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

dsentker/AvatarMaker

Repository files navigation

AvatarMaker

This class creates an GMail-like avatar image by given string (e.g. username).

Avatar demo images

Installation

$ composer require shiftedwork/avatarmaker

Usage

// choose 'circle' or 'column', 'diamond', 'random', 'rectangle' or 'rhomb' for avatar shape
$avatar = AvatarFactory::createAvatarMaker('circle', 64);

$avatar->setHues(['red', 'orange']);

// direct output
printf('<img alt="Avatar" src="%s"/>', $avatar->makeAvatar('John Doe')->toBase64());

Advanced Usage

$size = 128;
$manager = new ImageManager(['driver' => 'imagick']);
$shape = new Shift\AvatarMaker\Shape\Rhomb($manager, $size);    // create shape and define avatar size
$avatar = new AvatarMaker($shape);
$avatar->setBackgroundLuminosity('bright');                     // choose 'bright', 'light' or 'dark'
$avatar->setHues(['red', 'orange', 'yellow']);                  // set one or more hues
$avatar->setSeparator('@');                                     // define separator character(s) for name splitting
$avatar->setFontFile('path/to/font.ttf');
$avatar->setCharLength(3);                                      // default: 2 characters

// save to file
$avatarMaker->makeAvatar('hello.world@example.net')->save('path/to/user.png');

Testing

$ phpunit