PHP code example of zertex / avatar-generator

1. Go to this page and download the library: Download zertex/avatar-generator 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/ */

    

zertex / avatar-generator example snippets


$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');

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

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

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

TEXTURE_NAME . '-' . COLOR . '.png'