PHPackages                             avatarfy/avatarfy - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. avatarfy/avatarfy

ActiveLibrary

avatarfy/avatarfy
=================

Avatarfy - A comprehensive Laravel package for generating culturally-aware SVG avatars with expressions, age groups, and customizable features

v1.1.0(9mo ago)25↓100%MITHTMLPHP ^7.4|^8.0|^8.1|^8.2|^8.3

Since Aug 4Pushed 9mo agoCompare

[ Source](https://github.com/niravpatel143/avatarfy)[ Packagist](https://packagist.org/packages/avatarfy/avatarfy)[ Docs](https://github.com/niravpatel143/avatarfy)[ RSS](/packages/avatarfy-avatarfy/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

Avatarfy - SVG Avatar Generator
===============================

[](#avatarfy---svg-avatar-generator)

[![PHP Version](https://camo.githubusercontent.com/b43c9d6cd8939c4868f963284928566c4c35dd2da0725c027f95a3d62f2f0329/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e342532422d626c75652e737667)](https://php.net)[![License](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](LICENSE)[![Tests](https://camo.githubusercontent.com/b55d7b5279113a72386f15952ab1db95c1225c83e3e011e3f558b91762190d4e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54657374732d323125324632312d627269676874677265656e2e737667)](#testing)

A comprehensive PHP SVG avatar generator that creates diverse, customizable avatars and simple grid identicons with deterministic generation based on seeds.

🚀 **[View Complete Avatar Gallery](./test_output/index.html)** - 38+ Live Examples!
-----------------------------------------------------------------------------------

[](#-view-complete-avatar-gallery---38-live-examples)

### 🌟 Quick Preview

[](#-quick-preview)

   [![](https://raw.githubusercontent.com/niravpatel143/avatarfy/main/test_output/avatar_expr_happy.svg)](https://raw.githubusercontent.com/niravpatel143/avatarfy/main/test_output/avatar_expr_happy.svg)
 **Happy Expression**   [![](https://raw.githubusercontent.com/niravpatel143/avatarfy/main/test_output/avatar_alice.svg)](https://raw.githubusercontent.com/niravpatel143/avatarfy/main/test_output/avatar_alice.svg)
 **Female Avatar**   [![](https://raw.githubusercontent.com/niravpatel143/avatarfy/main/test_output/avatar_country_Japan.svg)](https://raw.githubusercontent.com/niravpatel143/avatarfy/main/test_output/avatar_country_Japan.svg)
 **Japan Style**   [![](https://raw.githubusercontent.com/niravpatel143/avatarfy/main/test_output/avatar_child1.svg)](https://raw.githubusercontent.com/niravpatel143/avatarfy/main/test_output/avatar_child1.svg)
 **Child Age Group**   [![](https://raw.githubusercontent.com/niravpatel143/avatarfy/main/test_output/avatar_NiravGoriya.svg)](https://raw.githubusercontent.com/niravpatel143/avatarfy/main/test_output/avatar_NiravGoriya.svg)
 **Email Avatar**  ### 🎯 **[→ Explore Full Gallery with All 38+ Avatars](./test_output/index.html)** 🎯

[](#--explore-full-gallery-with-all-38-avatars-)

### 🔄 Transform Showcase - Unique Rotations

[](#-transform-showcase---unique-rotations)

   [![](https://raw.githubusercontent.com/niravpatel143/avatarfy/main/test_output/custom_avatar_transform_rotate.svg)](https://raw.githubusercontent.com/niravpatel143/avatarfy/main/test_output/custom_avatar_transform_rotate.svg)
 **Rotated 25°**   [![](https://raw.githubusercontent.com/niravpatel143/avatarfy/main/test_output/custom_avatar_combined_flip_rotate.svg)](https://raw.githubusercontent.com/niravpatel143/avatarfy/main/test_output/custom_avatar_combined_flip_rotate.svg)
 **Flip + Rotate**   [![](https://raw.githubusercontent.com/niravpatel143/avatarfy/main/test_output/custom_avatar_transform_clip.svg)](https://raw.githubusercontent.com/niravpatel143/avatarfy/main/test_output/custom_avatar_transform_clip.svg)
 **Clipped Circle**   [![](https://raw.githubusercontent.com/niravpatel143/avatarfy/main/test_output/custom_avatar_combined_all_transforms.svg)](https://raw.githubusercontent.com/niravpatel143/avatarfy/main/test_output/custom_avatar_combined_all_transforms.svg)
 **All Effects**   [![](https://raw.githubusercontent.com/niravpatel143/avatarfy/main/test_output/custom_avatar_transform_scale.svg)](https://raw.githubusercontent.com/niravpatel143/avatarfy/main/test_output/custom_avatar_transform_scale.svg)
 **Scale + Rotate**  > **✨ NEW!** Each avatar can be uniquely rotated, scaled, flipped, and clipped for dynamic visual appeal!

### 🎯 Identicon Gallery - Simple Grid Patterns

[](#-identicon-gallery---simple-grid-patterns)

   [![](./test_output/identicon_user123.svg)](./test_output/identicon_user123.svg)
 **user123**   [![](./test_output/identicon_alice_smith.svg)](./test_output/identicon_alice_smith.svg)
 **alice\_smith**   [![](./test_output/identicon_john_doe.svg)](./test_output/identicon_john_doe.svg)
 **john\_doe**   [![](./test_output/identicon_github_user_123.svg)](./test_output/identicon_github_user_123.svg)
 **GitHub Style**   [![](./test_output/identicon_developer_01.svg)](./test_output/identicon_developer_01.svg)
 **developer\_01**  > **🎨 Identicons:** Perfect for GitHub-style geometric avatars - same seed always generates identical patterns!

✨ Features &amp; Capabilities
-----------------------------

[](#-features--capabilities)

### 🎨 **Visual Features** ([See Live Gallery](./test_output/index.html))

[](#-visual-features-see-live-gallery)

- **🎭 8 Expressions**: Happy, Sad, Surprised, Angry, Wink, Neutral, Confused, Laughing
- **🌍 8 Countries**: USA, India, China, UK, Germany, Japan, Brazil, Nigeria
- **👶 4 Age Groups**: Child, Teen, Adult, Senior (with age-appropriate characteristics)
- **⚡ 6 Personalities**: Confident, Energetic, Professional, Cheerful, Creative, Stylish
- **👤 Gender Aware**: Male/female specific traits (eyebrows, facial structure)
- **📧 Email Integration**: Smart avatar generation from email addresses with initials
- **🎨 SVG Transforms**: Flip, rotate, scale, border radius, circular clipping

### 🛠️ **Technical Features**

[](#️-technical-features)

- **⚡ Zero Dependencies**: Pure PHP implementation - no external libraries required
- **📐 SVG-based**: Scalable vector graphics for crisp avatars at any size
- **🚀 Lightning Fast**: Generate avatars in ~50ms with minimal memory usage
- **🎯 Smart Defaults**: Intelligent parameter generation based on user ID
- **🔧 Fully Customizable**: Control skin tone, eye color, glasses, and more
- **📱 Modern Design**: Clean, contemporary look with rounded corners

### 🌍 **Cultural Features**

[](#-cultural-features)

Each country includes:

- 🎨 **Unique Color Palettes**: Region-specific background colors
- 👤 **Skin Tone Preferences**: Culturally appropriate defaults
- 🎪 **Cultural Accessories**: Glasses, headwear, jewelry variations

> 🎯 **[View All Features in Action →](./test_output/index.html)** - Interactive gallery with 38+ examples!

🚀 Super Easy Installation
-------------------------

[](#-super-easy-installation)

### Step 1: Install Package

[](#step-1-install-package)

```
composer require avatarfy/avatarfy

```

### Step 2: Create Storage Directory

[](#step-2-create-storage-directory)

```
php artisan storage:link
```

### Step 3: Start Using! (No config needed)

[](#step-3-start-using-no-config-needed)

```
use Avatarfy\Services\SimpleSvgAvatarService;

$service = new SimpleSvgAvatarService([
    'width' => 256,
    'height' => 256,
    'storage_path' => storage_path('app/public/avatars'),
    'personalities' => [
        'friendly' => ['primary' => '#4CAF50', 'secondary' => '#8BC34A']
    ]
]);

// Generate avatar - that's it!
$avatarPath = $service->generateAvatar('user123');
```

### Optional: Advanced Setup

[](#optional-advanced-setup)

Publish config for advanced customization:

```
php artisan vendor:publish --provider="Avatarfy\AvatarServiceProvider" --tag="config"
```

Quick Start
-----------

[](#quick-start)

### Method 1: Simple Usage (Recommended)

[](#method-1-simple-usage-recommended)

```
use Avatarfy\Services\SimpleSvgAvatarService;

// Initialize with basic config
$service = new SimpleSvgAvatarService([
    'width' => 256,
    'height' => 256,
    'storage_path' => storage_path('app/public/avatars'),
    'personalities' => [
        'friendly' => ['primary' => '#4CAF50', 'secondary' => '#8BC34A']
    ]
]);

// Generate simple avatar
$avatarPath = $service->generateAvatar('user123');

// Generate from email (with initials)
$avatarPath = $service->generateFromEmail('john.doe@example.com');

// Generate comprehensive avatar
$avatarPath = $service->generateAvatar(
    'user123',                 // User ID
    25,                        // Age (determines age group)
    'female',                  // Gender: 'male' or 'female'
    'Japan',                   // Country
    'cheerful',                // Personality
    'laughing'                 // Expression
);

// Get public URL
$avatarUrl = asset('storage/avatars/' . basename($avatarPath));
```

### Method 2: Using Laravel Config (Advanced)

[](#method-2-using-laravel-config-advanced)

```
use Avatarfy\Services\SimpleSvgAvatarService;

class UserController extends Controller
{
    public function generateAvatar($userId)
    {
        // Use published config file
        $config = config('avatarfy');
        $service = new SimpleSvgAvatarService($config);

        $avatarPath = $service->generateAvatar($userId);
        $avatarUrl = asset('storage/avatars/' . basename($avatarPath));

        return response()->json(['avatar_url' => $avatarUrl]);
    }
}
```

### Method 3: Using the Facade

[](#method-3-using-the-facade)

```
use Avatarfy\Facades\AvatarGenerator;

// Generate simple avatar
$avatarPath = AvatarGenerator::generateAvatar('user123');

// Generate from email
$avatarPath = AvatarGenerator::generateFromEmail('jane@example.com');

// Generate custom avatar
$avatarPath = AvatarGenerator::generateCustomAvatar('user456', [
    'age' => 30,
    'gender' => 'male',
    'country' => 'Germany',
    'hasGlasses' => true,
    'expression' => 'wink'
]);
```

🎨 SVG Transform System - NEW!
-----------------------------

[](#-svg-transform-system---new)

Avaterfy now includes a powerful SVG transform system that lets you apply visual effects to your generated avatars!

### 🔧 Available Transform Options

[](#-available-transform-options)

TransformDescriptionExample ValueVisual Effect**`flip`**Horizontal flip`true`Mirror the avatar horizontally**`rotate`**Rotation in degrees`45`Rotate avatar clockwise**`scale`**Scale percentage`120`Make avatar 120% larger**`radius`**Border radius in pixels`20`Rounded corners on background**`clip`**Circular clipping`true`Crop avatar to perfect circle**`translate_x`**Horizontal offset`10`Move avatar horizontally**`translate_y`**Vertical offset`-5`Move avatar vertically### 🎯 Transform Usage Examples

[](#-transform-usage-examples)

#### Basic Individual Transforms

[](#basic-individual-transforms)

```
// Horizontally flipped avatar
$service->generateCustomAvatar('user1', [
    'expression' => 'happy',
    'flip' => true
]);

// Rotated avatar
$service->generateCustomAvatar('user2', [
    'expression' => 'wink',
    'rotate' => 30  // 30 degrees clockwise
]);

// Scaled avatar
$service->generateCustomAvatar('user3', [
    'expression' => 'laughing',
    'scale' => 150  // 150% size
]);

// Circular avatar
$service->generateCustomAvatar('user4', [
    'expression' => 'surprised',
    'clip' => true  // Perfect circle
]);

// Rounded corners
$service->generateCustomAvatar('user5', [
    'expression' => 'neutral',
    'radius' => 25  // 25px border radius
]);
```

#### Combined Transform Effects

[](#combined-transform-effects)

```
// Multiple transforms together
$service->generateCustomAvatar('showcase_user', [
    'age' => 28,
    'gender' => 'female',
    'country' => 'Brazil',
    'expression' => 'laughing',
    'skinTone' => 'medium_dark',
    'hasGlasses' => true,
    // Transform effects
    'flip' => true,        // Mirror horizontally
    'rotate' => 15,        // Slight rotation
    'scale' => 110,        // 10% larger
    'radius' => 20,        // Rounded corners
    'clip' => true         // Circular shape
]);
```

#### Dynamic Transform Generation

[](#dynamic-transform-generation)

```
// Random transform showcase
for ($i = 1; $i generateCustomAvatar("random_{$i}", [
        'age' => rand(20, 50),
        'gender' => ['male', 'female'][rand(0, 1)],
        'expression' => ['happy', 'wink', 'laughing'][rand(0, 2)],
        // Dynamic transforms
        'flip' => (bool)rand(0, 1),
        'rotate' => rand(-30, 30),
        'scale' => rand(80, 120),
        'radius' => rand(0, 25),
        'clip' => (bool)rand(0, 1)
    ]);
}
```

### 🎪 Transform Combinations

[](#-transform-combinations)

**Popular Transform Combinations:**

```
// Profile Picture Style
'clip' => true,
'scale' => 95,
'radius' => 10

// Dynamic Showcase
'flip' => true,
'rotate' => 20,
'scale' => 110

// Elegant Card Style
'radius' => 15,
'scale' => 105,
'translate_y' => -5

// Playful Style
'rotate' => rand(-15, 15),
'scale' => rand(95, 115),
'flip' => (bool)rand(0, 1)
```

### ⚡ Generated SVG Transform Code

[](#-generated-svg-transform-code)

The system automatically generates optimized SVG transform code:

```

```

### 🎨 Transform Test Gallery

[](#-transform-test-gallery)

**Run the transform test to see all effects:**

```
php test_transforms.php
```

This generates avatars showcasing:

- ✅ Individual transform effects
- ✅ Combined transform combinations
- ✅ All expressions with transforms
- ✅ Random showcase generation
- ✅ SVG validation and verification

### 🔧 Technical Implementation

[](#-technical-implementation)

Transforms are applied via the `applyTransforms()` method which:

1. **Validates** all transform parameters
2. **Combines** multiple transforms efficiently
3. **Optimizes** SVG transform strings
4. **Preserves** avatar centering and positioning
5. **Generates** clean, standards-compliant SVG code

**Transform Order (automatically optimized):**

1. Translation → 2. Rotation → 3. Scale → 4. Flip → 5. Clipping → 6. Border Radius

🎯 Identicon System - Geometric Avatars
--------------------------------------

[](#-identicon-system---geometric-avatars)

Generate GitHub-style geometric pattern avatars perfect for user profiles, comments, and placeholder images!

### 🔷 Identicon Features

[](#-identicon-features)

FeatureDescriptionBenefit**🎲 Deterministic**Same seed = same patternConsistent user avatars**🎨 Symmetric**5x5 mirrored gridVisually appealing patterns**💸 No Storage**Generated on-demandZero database overhead**⚡ Lightning Fast**~25ms generationFaster than face avatars**🌈 Unique Colors**Seeded color palettesDistinctive visual identity### 🎯 Identicon Usage Examples

[](#-identicon-usage-examples)

#### Basic Identicon Generation

[](#basic-identicon-generation)

```
// Simple identicon from username
$service->generateIdenticon('github_user_123');

// From email address
$service->generateIdenticon('user@example.com');

// From user ID
$service->generateIdenticon('user_456789');

// Custom seed string
$service->generateIdenticon('my_custom_seed_2023');
```

#### Custom Size Identicons

[](#custom-size-identicons)

```
// Small size for comments
$service->generateIdenticon('commenter_123', ['size' => 64]);

// Medium size for profiles
$service->generateIdenticon('profile_user', ['size' => 128]);

// Large size for headers
$service->generateIdenticon('header_logo', ['size' => 512]);

// Default size (256px)
$service->generateIdenticon('default_user');
```

#### Platform-Specific Identicons

[](#platform-specific-identicons)

```
// GitHub-style identicons
foreach (['alice_dev', 'bob_coder', 'charlie_admin'] as $username) {
    $service->generateIdenticon("github_{$username}");
}

// Forum user identicons
foreach (['user_001', 'user_002', 'user_003'] as $userId) {
    $service->generateIdenticon("forum_{$userId}", ['size' => 48]);
}

// Discord-style round identicons (use with transforms)
$service->generateCustomAvatar('discord_user', [
    'clip' => true  // Makes it circular
]);
// Then convert to identicon pattern if needed
```

### 🔄 Deterministic Generation

[](#-deterministic-generation)

**Same seed always produces identical patterns:**

```
// These will be identical
$avatar1 = $service->generateIdenticon('john_doe_123');
$avatar2 = $service->generateIdenticon('john_doe_123');
// avatar1 === avatar2 (same visual pattern)

// Different seed = different pattern
$avatar3 = $service->generateIdenticon('jane_doe_456');
// avatar3 !== avatar1 (completely different pattern)
```

### 🌈 Color Generation

[](#-color-generation)

Colors are deterministically generated from seeds:

```
// Each seed produces unique color combinations
$service->generateIdenticon('red_themed_user');    // Might generate red tones
$service->generateIdenticon('blue_themed_user');   // Might generate blue tones
$service->generateIdenticon('green_themed_user');  // Might generate green tones

// Same seed = same colors (always)
$service->generateIdenticon('consistent_colors'); // Always same palette
```

### 🎨 Real-World Use Cases

[](#-real-world-use-cases)

#### GitHub-Style User Profiles

[](#github-style-user-profiles)

```
class UserProfile {
    public function getAvatar($username) {
        // Try to get uploaded avatar first
        if ($this->hasUploadedAvatar($username)) {
            return $this->getUploadedAvatar($username);
        }

        // Fall back to identicon
        $service = new SimpleSvgAvatarService(config('avatarfy'));
        return $service->generateIdenticon($username);
    }
}
```

#### Comment System Avatars

[](#comment-system-avatars)

```
class CommentSystem {
    public function displayComment($comment) {
        $userId = $comment->user_id ?? 'anonymous_' . $comment->ip_hash;

        // Generate small identicon for comment avatar
        $service = new SimpleSvgAvatarService(config('avatarfy'));
        $avatarPath = $service->generateIdenticon($userId, ['size' => 40]);

        return [
            'comment' => $comment->text,
            'avatar' => asset('storage/avatars/' . basename($avatarPath)),
            'username' => $comment->username ?? 'Anonymous'
        ];
    }
}
```

#### Forum Signature Generation

[](#forum-signature-generation)

```
class ForumSignature {
    public function generateUserSignature($username, $postCount) {
        $service = new SimpleSvgAvatarService(config('avatarfy'));

        // Create identicon based on username + post count for uniqueness
        $seed = $username . '_posts_' . intval($postCount / 100); // Changes every 100 posts
        $avatarPath = $service->generateIdenticon($seed, ['size' => 64]);

        return $avatarPath;
    }
}
```

### 🎮 Gaming &amp; Social Platforms

[](#-gaming--social-platforms)

```
// Gaming platform user avatars
$service->generateIdenticon('gamer_' . $playerId, ['size' => 128]);

// Social media fallback avatars
$service->generateIdenticon('social_' . $socialId, ['size' => 256]);

// Chat application avatars
$service->generateIdenticon('chat_' . $userId, ['size' => 48]);

// Anonymous user identification
$service->generateIdenticon('anon_' . hash('md5', $sessionId), ['size' => 64]);
```

### 🔍 Technical Implementation

[](#-technical-implementation-1)

Identicons use a **5x5 symmetric grid pattern:**

```
[■][□][■][□][■]  generateAvatar('user789', 30, 'female');
```

### 📧 2. Email-Based Avatars

[](#-2-email-based-avatars)

```
// Simple email avatar (extracts initials)
$avatarPath = $service->generateFromEmail('john.doe@company.com');
// Result: Circular avatar with "JD" initials

// Email avatar with custom options
$avatarPath = $service->generateFromEmail('sarah@example.com', [
    'gender' => 'female',
    'expression' => 'happy',
    'age' => 28
]);
```

### 🎭 3. Expression &amp; Personality Avatars

[](#-3-expression--personality-avatars)

```
// Different expressions
foreach (['happy', 'wink', 'laughing', 'surprised'] as $expr) {
    $service->generateAvatar("user_${expr}", 25, 'female', 'USA', 'cheerful', $expr);
}

// Different personalities
foreach (['confident', 'energetic', 'professional', 'creative'] as $personality) {
    $service->generateAvatar("${personality}_user", 30, 'male', 'Germany', $personality);
}
```

### 🌍 4. Cultural &amp; Demographic Avatars

[](#-4-cultural--demographic-avatars)

```
// Country-specific avatars
$countries = ['USA', 'India', 'Japan', 'Brazil', 'Nigeria'];
foreach ($countries as $country) {
    $service->generateAvatar("user_${country}", 25, 'female', $country);
}

// Age group examples
$service->generateAvatar('child', 8);     // Child characteristics
$service->generateAvatar('teen', 16);     // Teen characteristics
$service->generateAvatar('adult', 35);    // Adult characteristics
$service->generateAvatar('senior', 70);   // Senior characteristics
```

### 🎨 5. Advanced Customization

[](#-5-advanced-customization)

```
// Full customization
$service->generateCustomAvatar('premium_user', [
    'age' => 32,
    'gender' => 'female',
    'country' => 'Japan',
    'personality' => 'creative',
    'expression' => 'wink',
    'skinTone' => 'light',           // Specific skin tone
    'eyeColor' => '#2E8B57',         // Custom eye color
    'hasGlasses' => true,            // Add glasses
    // Transform effects
    'flip' => false,
    'rotate' => 10,
    'scale' => 105,
    'radius' => 15,
    'clip' => false
]);
```

### 🎲 6. Deterministic Generation

[](#-6-deterministic-generation)

```
// Same seed = same avatar (always)
$seed = 'github_user_123';
$avatar1 = $service->generateFromSeed($seed);
$avatar2 = $service->generateFromSeed($seed);
// avatar1 and avatar2 are identical

// Seed with custom options
$service->generateFromSeed('discord_user_456', [
    'flip' => true,
    'scale' => 110,
    'expression' => 'laughing'
]);
```

### 🏭 7. Batch Generation

[](#-7-batch-generation)

```
// Batch generate with same options
$userIds = ['alice', 'bob', 'charlie', 'diana', 'eve'];
$results = $service->generateBatch($userIds, [
    'age' => 25,
    'country' => 'USA',
    'personality' => 'cheerful'
]);

// Process results
foreach ($results as $userId => $avatarPath) {
    echo "Avatar for {$userId}: {$avatarPath}\n";
}
```

### 🎯 8. Identicon Generation

[](#-8-identicon-generation)

```
// GitHub-style identicons
$service->generateIdenticon('github_user_123');
$service->generateIdenticon('stackoverflow_456');

// Custom size identicon
$service->generateIdenticon('discord_abc', ['size' => 128]);
```

### 🔄 9. Real-World Laravel Integration

[](#-9-real-world-laravel-integration)

```
class UserController extends Controller
{
    public function generateUserAvatar(Request $request, $userId)
    {
        $user = User::findOrFail($userId);

        $service = new SimpleSvgAvatarService([
            'width' => 256,
            'height' => 256,
            'storage_path' => storage_path('app/public/avatars')
        ]);

        // Generate based on user preferences
        $avatarPath = $service->generateCustomAvatar($user->username, [
            'age' => $user->age ?? 25,
            'gender' => $user->gender ?? 'male',
            'country' => $user->country ?? 'USA',
            'expression' => $request->get('expression', 'happy'),
            // Transform options from request
            'flip' => $request->boolean('flip'),
            'rotate' => $request->get('rotate', 0),
            'scale' => $request->get('scale', 100),
            'clip' => $request->boolean('circular'),
            'radius' => $request->get('radius', 0)
        ]);

        // Save avatar URL to user
        $user->avatar_url = asset('storage/avatars/' . basename($avatarPath));
        $user->save();

        return response()->json([
            'success' => true,
            'avatar_url' => $user->avatar_url
        ]);
    }

    public function generateFromUserEmail($email)
    {
        $service = new SimpleSvgAvatarService(config('avatarfy'));
        $avatarPath = $service->generateFromEmail($email);

        return asset('storage/avatars/' . basename($avatarPath));
    }
}

## 🧪 Testing & Demo Gallery

### 🎨 **Interactive Demo Gallery**
**[Open Live Gallery](./test_output/index.html)** to see all generated avatars in a beautiful, responsive showcase!

### 🔬 **Run Tests Locally**
```bash
php test_all_features.php
```

### 📊 **Test Coverage**

[](#-test-coverage)

Our comprehensive test suite generates **38+ avatars** demonstrating:

Feature CategoryExamplesGallery Section🎭 **Expressions**8 variationsHappy, Sad, Surprised, Angry, Wink, Neutral, Confused, Laughing🌍 **Countries**8 culturesUSA, India, China, UK, Germany, Japan, Brazil, Nigeria👶 **Age Groups**4 stagesChild, Teen, Adult, Senior⚡ **Personalities**6 typesConfident, Energetic, Professional, Cheerful, Creative, Stylish📧 **Email Avatars**4 examplesSmart initials extraction and generation🎛️ **Custom Options**AdvancedCustom colors, glasses, skin tones### 📈 **Performance Metrics**

[](#-performance-metrics)

- ⚡ **Generation Speed**: ~50ms per avatar
- 📦 **File Size**: 2-4KB per SVG
- 🧠 **Memory Usage**: Minimal (no image processing)
- ♾️ **Scalability**: Infinite (vector-based)

**[→ View Performance in Action](./test_output/index.html)**

📁 Package Structure
-------------------

[](#-package-structure)

```
📦 avatarfy/
├── 🎨 test_output/
│   ├── index.html                        # 🌟 INTERACTIVE DEMO GALLERY
│   └── *.svg                            # 38+ Generated avatar examples
├── 🛠️ src/
│   ├── AvatarServiceProvider.php        # Laravel service provider
│   ├── Facades/AvatarGenerator.php      # Laravel facade
│   └── Services/
│       └── SimpleSvgAvatarService.php   # Main avatar generation engine
├── ⚙️ config/
│   └── avatarfy.php                     # Configuration file
├── 📚 examples/
│   ├── AvatarController.php             # Laravel controller example
│   ├── avatar-form.blade.php            # Blade template example
│   └── routes-example.php               # Route examples
├── 🧪 tests/
│   └── AvatarServiceTest.php            # Test suite
├── 🚀 test_all_features.php             # Comprehensive test runner
├── 📖 README.md                         # Documentation
└── 📋 composer.json                     # Package definition

```

### 🌟 **Key Files**

[](#-key-files)

- 🎨 **[test\_output/index.html](./test_output/index.html)** - Interactive demo gallery
- 🛠️ **SimpleSvgAvatarService.php** - Core avatar generation logic
- 🚀 **test\_all\_features.php** - Run all tests and generate gallery
- ⚙️ **avatarfy.php** - Full configuration options

🏆 Why Choose Avatarfy?
----------------------

[](#-why-choose-avatarfy)

### 🎯 **See It In Action**

[](#-see-it-in-action)

**[Interactive Demo Gallery](./test_output/index.html)** - Browse 38+ real examples!

### ⚡ **Performance Excellence**

[](#-performance-excellence)

- **🚀 Lightning Fast**: Generate avatars in ~50ms
- **📦 Tiny Files**: 2-4KB SVG files (vs 50KB+ PNG)
- **🧠 Memory Efficient**: No image processing overhead
- **♾️ Infinitely Scalable**: Vector graphics scale perfectly
- **🌐 Cross-platform**: Works on any PHP environment

### 🎨 **Design Excellence**

[](#-design-excellence)

- **🎭 Rich Expressions**: 8 distinct facial expressions
- **🌍 Cultural Awareness**: 8 countries with unique features
- **👶 Age Appropriate**: Realistic child to senior characteristics
- **📧 Smart Generation**: Email-to-avatar with initials
- **🎨 Modern Aesthetic**: Clean, contemporary design

### 🛠️ **Developer Experience**

[](#️-developer-experience)

- **📦 Zero Dependencies**: Pure PHP - no external libraries
- **🔧 Laravel Ready**: Service provider, facade, config included
- **🎯 Smart Defaults**: Works great out-of-the-box
- **🔒 Type Safe**: Full parameter validation
- **📚 Well Documented**: Comprehensive examples and docs

**[→ Try the Live Gallery](./test_output/index.html)**

License
-------

[](#license)

This project is open source. Feel free to use, modify, and distribute.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance62

Regular maintenance activity

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Total

2

Last Release

273d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8b1da9c6278144d942bacc8ee59e21c4b82543388c8008c52b98c2d5a49ed86c?d=identicon)[Nirav Goriya](/maintainers/Nirav%20Goriya)

---

Top Contributors

[![niravpatel143](https://avatars.githubusercontent.com/u/70512652?v=4)](https://github.com/niravpatel143 "niravpatel143 (13 commits)")

---

Tags

laravelgeneratorsvgexpressionsprofileavatarculturaldemographicsavatarfy

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/avatarfy-avatarfy/health.svg)

```
[![Health](https://phpackages.com/badges/avatarfy-avatarfy/health.svg)](https://phpackages.com/packages/avatarfy-avatarfy)
```

###  Alternatives

[laravolt/avatar

Turn name, email, and any other string into initial-based avatar or gravatar.

2.0k5.4M31](/packages/laravolt-avatar)[multiavatar/multiavatar-php

Multicultural Avatar Generator

653150.0k4](/packages/multiavatar-multiavatar-php)[ultrono/laravel-sitemap

Sitemap generator for Laravel 11, 12 and 13

36412.6k6](/packages/ultrono-laravel-sitemap)[tomloprod/radiance

A deterministic mesh gradient avatar generator for PHP.

1393.7k](/packages/tomloprod-radiance)[dcblogdev/laravel-module-generator

Generate Laravel Modules from a template.

7710.1k1](/packages/dcblogdev-laravel-module-generator)[romegasoftware/laravel-schema-generator

Generate TypeScript Zod validation schemas from Laravel validation rules

288.2k](/packages/romegasoftware-laravel-schema-generator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
