PHPackages                             yzalis/identicon - 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. [Image &amp; Media](/categories/media)
4. /
5. yzalis/identicon

ActiveLibrary[Image &amp; Media](/categories/media)

yzalis/identicon
================

Generate unique identicon avatars from any string

v3.0.0(3mo ago)5901.1M↓20.8%9820MITPHPPHP &gt;=8.2

Since Aug 16Pushed 3mo ago15 watchersCompare

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

READMEChangelogDependencies (4)Versions (8)Used By (20)

Identicon
=========

[](#identicon)

[![CI](https://camo.githubusercontent.com/f40a6c9ebe2f7d7a770b0044aa2bcab5ca6d42a70b3271eff740e4d31c010eda/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f797a616c69732f4964656e7469636f6e2f63692e796d6c3f7374796c653d666c61742d737175617265266c6f676f3d676974687562266c6162656c3d4349)](https://github.com/yzalis/Identicon/actions/workflows/ci.yml)[![Latest Version](https://camo.githubusercontent.com/933614275083ee92fcae454d5a38348cd21b98d22113fe7547c8b2e609ef264c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f797a616c69732f6964656e7469636f6e3f7374796c653d666c61742d737175617265266c6f676f3d7061636b6167697374266c6f676f436f6c6f723d7768697465)](https://packagist.org/packages/yzalis/identicon)[![PHP Version](https://camo.githubusercontent.com/7c8fc2f600aa32366c4acc1d808809b07e273e31ea48147f101c5dd768f41269/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f797a616c69732f6964656e7469636f6e3f7374796c653d666c61742d737175617265266c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://www.php.net/)[![Downloads](https://camo.githubusercontent.com/2da611af439576a8a80aa059e2f02f0c3c2898aaafdee40bebfde065b7147df1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f797a616c69732f6964656e7469636f6e3f7374796c653d666c61742d737175617265266c6f676f3d7061636b6167697374266c6f676f436f6c6f723d7768697465)](https://packagist.org/packages/yzalis/identicon)[![License](https://camo.githubusercontent.com/e1f5535402762aeffdfa6cc91879c9205a0d1fa45c5d453ae73d051c23286aab/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f797a616c69732f4964656e7469636f6e3f7374796c653d666c61742d737175617265)](LICENSE)

Generate unique identicon avatars from any string.

Installation
------------

[](#installation)

```
composer require yzalis/identicon
```

Requirements
------------

[](#requirements)

- PHP 8.1+
- GD extension (for PNG output) or Imagick extension (optional)

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

[](#quick-start)

```
use Yzalis\Identicon\Identicon;

// Generate a data URI for an img tag
$dataUri = Identicon::generate('john@example.com');
echo '';

// With custom size
$dataUri = Identicon::generate('john@example.com', 128);
```

Builder Pattern
---------------

[](#builder-pattern)

For more control, use the fluent builder:

```
use Yzalis\Identicon\IdenticonBuilder;

$identicon = (new IdenticonBuilder())
    ->size(256)
    ->gridSize(7)
    ->margin(16)
    ->color('#3498db')
    ->backgroundColor('#ffffff')
    ->useSvg()
    ->build();

$svg = $identicon->getImageData('john@example.com');
$dataUri = $identicon->getImageDataUri('john@example.com');
```

Configuration Options
---------------------

[](#configuration-options)

### Size

[](#size)

```
// Square image
$builder->size(128);  // 128x128 pixels

// Rectangle (if needed)
$builder->dimensions(200, 100);
```

### Grid Size

[](#grid-size)

The grid determines the pattern complexity (default: 5x5).

```
$builder->gridSize(7);  // 7x7 grid

// Auto-calculate based on image size
$builder->size(1024)->autoGridSize();  // ~17x17 grid
```

### Margins

[](#margins)

```
// Uniform margin
$builder->margin(16);  // 16px all sides

// Percentage margin
$builder->marginPercent(10);  // 10% of image size

// Per-side margin
$builder->margin([10, 20, 10, 20]);  // top, right, bottom, left
```

### Colors

[](#colors)

```
// Hex colors
$builder->color('#3498db');
$builder->color('fff');  // Short format

// RGB array
$builder->color([52, 152, 219]);

// Background
$builder->backgroundColor('#ffffff');
$builder->backgroundColor(null);  // Transparent (default)
```

### Renderers

[](#renderers)

```
$builder->useSvg();         // SVG (vector, no extension needed)
$builder->useGd();          // PNG via GD (default)
$builder->useImageMagick(); // PNG via ImageMagick
```

### Hash Algorithms

[](#hash-algorithms)

```
$builder->useSha256();  // Default, better distribution
$builder->useMd5();     // For v2 compatibility
```

### Pre-computed Hashes (GDPR Compliance)

[](#pre-computed-hashes-gdpr-compliance)

If you already have pre-computed hashes (e.g., for GDPR compliance where emails are stored as hashes), you can generate identicons directly from those hashes without re-hashing:

```
// Database stores hashed emails for privacy (GDPR)
$storedHash = 'acbd18db4cc2f85cedef654fccc4a4d8';  // MD5 of user email

$identicon = (new IdenticonBuilder())
    ->skipHashing()  // Use input directly as hash
    ->useSvg()
    ->build();

$avatar = $identicon->getImageDataUri($storedHash);
```

This ensures consistency: generating an identicon from `"john@example.com"` with MD5 hashing produces the same result as generating from its pre-computed MD5 hash with `skipHashing()` enabled.

```
// These produce identical identicons:
$email = 'john@example.com';
$hash = md5($email);

// Method 1: Hash the email
$id1 = (new IdenticonBuilder())->useMd5()->build();
$avatar1 = $id1->getImageData($email);

// Method 2: Use pre-computed hash directly
$id2 = (new IdenticonBuilder())->skipHashing()->build();
$avatar2 = $id2->getImageData($hash);

// $avatar1 === $avatar2
```

Output Methods
--------------

[](#output-methods)

```
$identicon = (new IdenticonBuilder())->build();

// Get binary image data
$data = $identicon->getImageData('email@example.com');

// Get base64 data URI (for img src)
$dataUri = $identicon->getImageDataUri('email@example.com');

// Get raw base64 string
$base64 = $identicon->getImageBase64('email@example.com');

// Output directly to browser
$identicon->displayImage('email@example.com');

// Save to file
$identicon->saveToFile('email@example.com', '/path/to/avatar.png');

// Get the generated color
$color = $identicon->getColor('email@example.com');
echo $color->toHex();  // #3498db
```

v2 Compatibility
----------------

[](#v2-compatibility)

If you're upgrading from v2 and need to keep the same identicons:

```
$identicon = (new IdenticonBuilder())
    ->useV2Compatibility()
    ->build();
```

This activates:

- MD5 hashing (instead of SHA-256)
- Legacy color extraction algorithm
- 5x5 grid

See [UPGRADE-3.0.md](UPGRADE-3.0.md) for full migration guide.

Advanced Usage
--------------

[](#advanced-usage)

### Custom Algorithms

[](#custom-algorithms)

```
use Yzalis\Identicon\Algorithm\HashAlgorithmInterface;
use Yzalis\Identicon\Value\Hash;

class MyHashAlgorithm implements HashAlgorithmInterface
{
    public function hash(string $input): Hash
    {
        return new Hash(hash('sha512', $input));
    }

    public function getName(): string
    {
        return 'sha512';
    }
}

$identicon = (new IdenticonBuilder())
    ->hashAlgorithm(new MyHashAlgorithm())
    ->build();
```

### Custom Renderers

[](#custom-renderers)

```
use Yzalis\Identicon\Renderer\RendererInterface;

class WebPRenderer implements RendererInterface
{
    // Implement render(), getMimeType(), getFileExtension(), isAvailable()
}

$identicon = (new IdenticonBuilder())
    ->renderer(new WebPRenderer())
    ->build();
```

Testing
-------

[](#testing)

```
composer install
composer test
```

Static Analysis
---------------

[](#static-analysis)

```
composer analyze
```

Code Style
----------

[](#code-style)

```
composer cs       # Check
composer cs:fix   # Fix
```

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) for details.

Credits
-------

[](#credits)

- Benjamin Laugueux
- [All contributors](https://github.com/yzalis/Identicon/graphs/contributors)

Inspired by GitHub's [blog post](https://github.com/blog/1586-identicons) about identicons.

###  Health Score

68

—

FairBetter than 100% of packages

Maintenance80

Actively maintained with recent releases

Popularity61

Solid adoption and visibility

Community36

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 53.5% 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 ~910 days

Recently: every ~1055 days

Total

6

Last Release

105d ago

Major Versions

1.2.0 → 2.0.02019-10-14

2.0.0 → v3.0.02026-02-03

PHP version history (3 changes)1.0.0PHP &gt;=5.3.0

1.2.0PHP &gt;=5.5.0

v3.0.0PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/67c8faeb53542848865b901c6ed936f0d1254caabe83ede2bb7e8b61853bd3f9?d=identicon)[blaugueux](/maintainers/blaugueux)

---

Top Contributors

[![blaugueux](https://avatars.githubusercontent.com/u/767963?v=4)](https://github.com/blaugueux "blaugueux (53 commits)")[![lucasmichot](https://avatars.githubusercontent.com/u/513603?v=4)](https://github.com/lucasmichot "lucasmichot (40 commits)")[![F21](https://avatars.githubusercontent.com/u/2263040?v=4)](https://github.com/F21 "F21 (1 commits)")[![Grummfy](https://avatars.githubusercontent.com/u/668804?v=4)](https://github.com/Grummfy "Grummfy (1 commits)")[![johannesschobel](https://avatars.githubusercontent.com/u/9431350?v=4)](https://github.com/johannesschobel "johannesschobel (1 commits)")[![arjenm](https://avatars.githubusercontent.com/u/4731905?v=4)](https://github.com/arjenm "arjenm (1 commits)")[![TheHiddenHaku](https://avatars.githubusercontent.com/u/5628820?v=4)](https://github.com/TheHiddenHaku "TheHiddenHaku (1 commits)")[![dalecgu](https://avatars.githubusercontent.com/u/7344018?v=4)](https://github.com/dalecgu "dalecgu (1 commits)")

---

Tags

imagehashsvgpngavataridenticonunique

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[picqer/php-barcode-generator

An easy to use, non-bloated, barcode generator in PHP. Creates SVG, PNG, JPG and HTML images from the most used 1D barcode standards.

1.8k25.5M88](/packages/picqer-php-barcode-generator)[lasserafn/php-initial-avatar-generator

A package to generate avatars with initials for PHP

4374.2M13](/packages/lasserafn-php-initial-avatar-generator)[multiavatar/multiavatar-php

Multicultural Avatar Generator

653150.0k4](/packages/multiavatar-multiavatar-php)[jkphl/iconizr

A PHP command line tool for converting SVG images to a set of CSS icons (SVG &amp; PNG, single icons and / or CSS sprites) with support for image optimization and Sass output

4869.0k](/packages/jkphl-iconizr)[jdenticon/jdenticon

Render PNG and SVG identicons.

60393.1k5](/packages/jdenticon-jdenticon)[irazasyed/laravel-identicon

Laravel Identicon Package

2329.5k1](/packages/irazasyed-laravel-identicon)

PHPackages © 2026

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