maxvoronov/avatarix

Avatars generating library

0.1.0 2018-08-05 03:22 UTC

This package is not auto-updated.

Last update: 2024-04-23 15:14:42 UTC


README

Install

The preferred way to install this extension is through composer:

composer require maxvoronov/avatarix

Usage

Library can generate 8-bits avatar by any string. This package use Imagine for processing.

use MaxVoronov\Avatarix;
use MaxVoronov\Avatarix\SpriteCollection;

$avatarix = new Avatarix;
$avatarix->setPayload('username');       // You can use here user ID or email

$avatarix                                // Set collections of avatar parts
    ->appendCollection(SpriteCollection::init(__DIR__ . '/assets/bg/'))
    ->appendCollection(SpriteCollection::init(__DIR__ . '/assets/faces/'))
    ->appendCollection(SpriteCollection::init(__DIR__ . '/assets/clothes/'))
    ->appendCollection(SpriteCollection::init(__DIR__ . '/assets/mouths/'))
    ->appendCollection(SpriteCollection::init(__DIR__ . '/assets/eyes/'))
    ->appendCollection(SpriteCollection::init(__DIR__ . '/assets/hairs/'));

$userAvatar = $avatarix->render();
$userAvatar->save('/path/to/avatar.png');       // Save generated avatar into file
$userAvatar->show('png');                       // ... and output with image headers

You can also look at an example.

Special Thanks

Special thanks to @matveyco and his 8biticon Project for avatar sprites.

License

The MIT License (MIT). Please see License File for more information.