renfordt/avatar-smithy

A modern PHP package that bundles multiple avatar generation engines. Forge beautiful avatars with ease.

Maintainers

Package info

codeberg.org/renfordt/AvatarSmithy

Issues

pkg:composer/renfordt/avatar-smithy

Transparency log

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

dev-main 2026-06-17 20:29 UTC

This package is auto-updated.

Last update: 2026-07-08 08:01:15 UTC


README

![Preview Image](preview.png "AvatarSmithy Preview") # AvatarSmithy **Forge beautiful avatars with ease.** [![Badge](http://img.shields.io/badge/source-renfordt/AvatarSmithy-blue.svg)](https://codeberg.org/renfordt/AvatarSmithy) [![Packagist Version](https://img.shields.io/packagist/v/renfordt/avatar-smithy)](https://packagist.org/packages/renfordt/avatar-smithy/) ![Packagist PHP Version](https://img.shields.io/packagist/dependency-v/renfordt/avatar-smithy/php) [![status-badge](https://ci.renfordt.dev/api/badges/5/status.svg)](https://ci.renfordt.dev/repos/5) [![Quality Gate Status](https://sonar.renfordt.dev/api/project_badges/measure?project=AvatarSmithy&metric=alert_status&token=sqb_7c5947e73f367396cb67a5d872c75b4391073fa2)](https://sonar.renfordt.dev/dashboard?id=AvatarSmithy) [![Coverage](https://sonar.renfordt.dev/api/project_badges/measure?project=AvatarSmithy&metric=coverage&token=sqb_7c5947e73f367396cb67a5d872c75b4391073fa2)](https://sonar.renfordt.dev/dashboard?id=AvatarSmithy) A modern PHP library that bundles **7 avatar generation engines** into a unified, fluent API. Create stunning avatars from user data with automatic fallback support and extensive customization. [Installation](#installation) • [Quick Start](#quick-start) • [Engines](#available-engines) • [Contributing](CONTRIBUTING.md)

Features

  • 7 Built-in Engines — From SVG initials to pixel art, Gravatar integration, and more
  • Fluent API — Intuitive builder pattern for effortless configuration
  • Smart Fallback — Automatic failover between engines ensures reliability
  • Flexible Output — Export as HTML, Base64, URLs, PSR-7 responses, or stream directly
  • Highly Customizable — Extensive styling options for each engine
  • Framework Agnostic — Works standalone or integrates seamlessly with Laravel/Symfony
  • Type Safe — Built with strict types and PHPStan level max
  • Modern PHP — Requires PHP 8.4+ with latest language features

Requirements

  • PHP 8.4 or higher
  • GD extension
  • Composer

Installation

Install via Composer:

composer require renfordt/avatar-smithy

Quick Start

Basic Usage

Generate an avatar with just a few lines:

use Renfordt\AvatarSmithy\Avatar;

// Simple avatar with email seed
$avatar = Avatar::engine('initials')
    ->seed('john.doe@example.com')
    ->name('John Doe')
    ->generate();

echo $avatar; // Outputs HTML img tag

Smart User Factory

Automatically extract email and name from user objects or arrays:

// Works with objects
$user = new User(['email' => 'jane@example.com', 'name' => 'Jane Smith']);
$avatar = Avatar::for($user)
    ->try('initials')
    ->size(300)
    ->generate();

// Works with arrays
$userData = ['email' => 'bob@example.com', 'name' => 'Bob Wilson'];
$avatar = Avatar::for($userData)
    ->try('gravatar')
    ->fallbackTo('initials')
    ->generate();

Available Engines

EngineDescriptionNetworkExample Use Case
initialsSVG avatars with user initials in colored shapesDefault user profiles
gravatarFetches from Gravatar.com based on email hashBlog comments, social platforms
dicebearFetches from DiceBear API (various styles)Fun, cartoon-style avatars
pixelGenerates retro pixel-art style avatarsGaming platforms, retro themes
multicolor-pixelMulti-colored variant of pixel engineVibrant pixel art avatars
bauhausBauhaus-inspired geometric art avatarsModern, artistic profiles
gradientBeautiful gradient-based avatarsMinimalist, colorful designs

[!TIP] Engines marked with ❌ generate avatars locally without network requests, while ✅ engines fetch from external APIs.

Output Formats

AvatarSmithy provides multiple output formats for maximum flexibility. Pick the method that matches where the avatar needs to go:

echo $avatar;                           // Auto-converts to an HTML <img> tag
$avatar->toHtml();                      // <img src="data:image/svg+xml;base64,..." alt="Avatar">
$avatar->toBase64();                    // data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAwIi...
$avatar->toUrl();                       // Gravatar: https://gravatar.com/... | Local:    data:image/svg+xml;base64,...
$avatar->save('/path/to/avatar.svg');   // Writes the avatar to the filesystem

// In a Laravel/Symfony controller
use Renfordt\AvatarSmithy\Http\AvatarResponder;

$avatar = Avatar::for($user)
    ->try('gravatar')
    ->fallbackTo('initials')
    ->generate();

return (new AvatarResponder($avatar))->toResponse();

[!TIP] Need a PSR-7 response? Build one from $avatar->getContent() and $avatar->getContentType() using your framework's PSR-17 factory.

Documentation

You can find the full documentation on this page: Documentation

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for details on:

  • Development setup and testing
  • Code quality standards
  • Architecture overview
  • Creating custom engines
  • Pull request process

License

This package is open-source software licensed under the MIT license.

Credits

Built with: