PHP code example of maxvoronov / avatarix

1. Go to this page and download the library: Download maxvoronov/avatarix library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

maxvoronov / avatarix example snippets


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