renfordt/avatar-smithy
Composer 安装命令:
composer require renfordt/avatar-smithy
包简介
A modern PHP package that bundles multiple avatar generation engines. Forge beautiful avatars with ease.
关键字:
README 文档
README
AvatarSmithy
Forge beautiful avatars with ease.
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 • Quick Start • Engines • Examples • Contributing
✨ 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();
Fallback Chain
Create a robust avatar system with automatic fallbacks:
$avatar = Avatar::engine('gravatar') ->fallbackTo('dicebear') ->fallbackTo('initials') // Final fallback always succeeds ->seed('user@example.com') ->name('User Name') ->size(256) ->generate();
🎨 Available Engines
| Engine | Description | Network | Example Use Case |
|---|---|---|---|
initials |
SVG avatars with user initials in colored shapes | ❌ | Default user profiles |
gravatar |
Fetches from Gravatar.com based on email hash | ✅ | Blog comments, social platforms |
dicebear |
Fetches from DiceBear API (various styles) | ✅ | Fun, cartoon-style avatars |
pixel |
Generates retro pixel-art style avatars | ❌ | Gaming platforms, retro themes |
multicolor-pixel |
Multi-colored variant of pixel engine | ❌ | Vibrant pixel art avatars |
bauhaus |
Bauhaus-inspired geometric art avatars | ❌ | Modern, artistic profiles |
gradient |
Beautiful gradient-based avatars | ❌ | Minimalist, 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:
⚙️ Configuration Options
Universal Options
These options work across all engines:
Avatar::engine('initials') ->seed('unique-identifier') // Seed for deterministic generation ->name('John Doe') // User's display name ->size(200) // Avatar size in pixels (default: 200) ->generate();
Engine-Specific Options
Initials Engine
Avatar::engine('initials') ->name('John Doe') ->size(256) ->shape('circle') // 'circle' or 'square' ->bold(true) // Bold font weight ->fontSize(100) // Custom font size ->backgroundColor(['#FF6B6B', '#4ECDC4', '#45B7D1']) // Color palette ->generate();
Gravatar Engine
Avatar::engine('gravatar') ->seed('user@example.com') // Email address ->size(256) ->defaultImage('identicon') // '404', 'mp', 'identicon', 'monsterid', // 'wavatar', 'retro', 'robohash', 'blank' ->rating('g') // 'g', 'pg', 'r', 'x' ->generate();
DiceBear Engine
Avatar::engine('dicebear') ->seed('user@example.com') ->size(256) ->style('avataaars') // DiceBear style (e.g., 'avataaars', 'bottts') ->backgroundColor('#FF6B6B') // Hex color ->radius(10) // Border radius ->generate();
Pixel Engines
// Single color pixel Avatar::engine('pixel') ->seed('user@example.com') ->size(256) ->pixels(5) // Grid size (5x5 pixels) ->symmetry(true) // Mirror horizontally ->foregroundLightness(0.4) // Lightness of colored pixels (0.0-1.0) ->backgroundLightness(0.9) // Lightness of background (0.0-1.0) ->generate(); // Multi-color pixel Avatar::engine('multicolor-pixel') ->seed('user@example.com') ->size(256) ->pixels(6) ->symmetry(true) ->numColors(4) // Number of colors in palette ->backgroundLightness(0.95) ->generate();
Bauhaus Engine
Avatar::engine('bauhaus') ->seed('user@example.com') ->size(256) ->numShapes(5) // Number of geometric shapes ->numColors(3) // Color palette size ->fillAll(false) // Whether to fill entire canvas ->generate();
Gradient Engine
Avatar::engine('gradient') ->seed('user@example.com') ->size(256) ->gradientType('linear') // 'linear' or 'radial' ->colorStops(3) // Number of color stops ->generate();
💎 Advanced Examples
Laravel Integration
// routes/web.php Route::get('/avatar/{user}', function (User $user) { return Avatar::for($user) ->try('gravatar') ->fallbackTo('initials') ->size(400) ->toResponse(); }); // In a Blade template <img src="{{ route('avatar', $user) }}" alt="{{ $user->name }}">
Custom Styling with Fallback Chain
$avatar = Avatar::for($user) ->try('gravatar') ->fallbackTo('dicebear') ->fallbackTo('initials') ->size(300) ->defaultImage('404') // Gravatar: fail if not found ->style('avataaars') // DiceBear: cartoon style ->shape('circle') // Initials: circular shape ->bold(true) // Initials: bold text ->generate();
Batch Generation
$users = User::all(); $avatars = []; foreach ($users as $user) { $avatars[$user->id] = Avatar::for($user) ->try('initials') ->size(150) ->generate() ->toBase64(); }
Dynamic Engine Selection
function generateAvatar(array $user, string $preferredEngine = 'initials'): string { return Avatar::for($user) ->try($preferredEngine) ->fallbackTo('initials') ->size(200) ->generate() ->toHtml(); } // Usage echo generateAvatar($user, 'pixel'); echo generateAvatar($adminUser, 'gravatar');
🤝 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
Created by renfordt
Built with:
- meyfa/php-svg — SVG generation
- renfordt/colors — Color manipulation
- renfordt/clamp — Value clamping
⚒️ Forge beautiful avatars with AvatarSmithy ⚒️
renfordt/avatar-smithy 适用场景与选型建议
renfordt/avatar-smithy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「gravatar」 「php」 「avatar」 「svg」 「bauhaus」 「gradient」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 renfordt/avatar-smithy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 renfordt/avatar-smithy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 renfordt/avatar-smithy 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A library providing easy gravatar integration/generation (Laravel supported).
Generate an Adorable Avatar for Laravel
Library to validate and parse social media profile URLs
Change the default avatar url provider with one for inline SVGs
Avatar extension for Contao Open Source CMS
This Twig extension generates user avatar using name initials letter inside Twig templates
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 32
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-21