m2code/avatar

Flexible and deterministic avatar generator

Maintainers

Package info

github.com/marijmokoginta/avatar

pkg:composer/m2code/avatar

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.2 2026-04-06 09:54 UTC

This package is auto-updated.

Last update: 2026-04-06 09:57:10 UTC


README

Flexible and deterministic avatar generator library, ready for Laravel integration.

Installation

composer require m2code/avatar

Laravel Usage (Facade)

use M2Code\Avatar\Facades\Avatar;

$result = Avatar::make('Marij Mokoginta')->generate();

echo $result->type;    // svg
echo $result->mime;    // image/svg+xml
echo $result->content; // SVG content
echo $result->toBase64();

Or use Laravel alias directly:

$result = \Avatar::make('Marij Mokoginta')->generate();

Standalone Usage (No Laravel)

use M2Code\Avatar\Application\Avatar\Avatar;

$result = Avatar::make('Marij Mokoginta')
    ->size(128)
    ->initials(2)
    ->background('#ff0000')
    ->generate();

Laravel Configuration

Publish config:

php artisan vendor:publish --tag=avatar-config

Configuration

Default config is in config/avatar.php:

return [
    'default_driver' => 'initial',
    'initial' => [
        'length' => 2,
        'size' => 100,
        'font_size' => 40,
        'background' => 'auto',
    ],
];

background => auto means deterministic color based on the seed hash.

Testing

composer test

Architecture

  • Application: Fluent entrypoint for avatar generation.
  • AvatarServiceProvider: Laravel integration layer.
  • Domain: Contracts and value objects.
  • Drivers: Concrete avatar generators.
  • Core/Resolvers: Driver resolver.
  • Support: Internal config reader.
  • Facades: Laravel facade entrypoint (Avatar).

Notes

  • Deterministic output based on seed.
  • No storage integration included.
  • Designed as foundation for future drivers.