PHP code example of murtaza1904 / avatar-generator

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

    

murtaza1904 / avatar-generator example snippets


return [
    'width' => 128,
    'color' => '#ffffff',
    'format' => 'png',
    'storage' => storage_path('app/public/avatars'),
    'filename_pattern' => '{name}-{timestamp}.{ext}',
    'palette' => [
        '#1abc9c','#2ecc71','#3498db','#9b59b6','#34495e',
        '#16a085','#27ae60','#2980b9','#8e44ad','#2c3e50',
        '#f39c12','#d35400','#c0392b','#7f8c8d','#e67e22',
    ],
];

use murtaza1904\AvatarGenerator\Facades\Avatar;

// Save avatar to default storage (config/avatar.php → storage)
$filename = Avatar::create('John Doe')
    ->size(128)
    ->background('#3498db')
    ->color('#ffffff')
    ->format('png')
    ->save();

echo $filename; // john-doe-1695382930.png

$filename = Avatar::create('Jane Smith')
    ->filename('custom-avatar.png')
    ->path(storage_path('app/public/avatars'));

$svg = Avatar::create('Ali Khan')
    ->format('svg')
    ->render();

echo $svg; // outputs SVG XML string
bash
php artisan vendor:publish --tag=avatar-config