A PHP library for generating identicons.
PHP-Identicons is a lightweight PHP implementation of Don Park's original identicon code for visual representation of MD5 hash values. The program uses the PHP GD library for image processing., (*1)
The code can be used to generate unique identicons, avatars, and system-assigned images based on a user's e-mail address, user ID, etc., (*2)
Install using composer:, (*3)
$ composer require fivenp/identicon
The code below, will create an identicon from the string "TEST", and save it to identicon.png
., (*4)
<?php use Fivenp\Identicon\Identicon; $identicon = new Identicon(md5('TEST')); $icon = $identicon->create(); file_put_contents('identicon.png', $icon);
There's also a shorter version of doing this:, (*5)
<?php use Fivenp\Identicon\Identicon; file_put_contents('identicon.png', (new Identicon(md5('TEST')))->create());
You can overwrite some basic settings by passing an options
array., (*6)
<?php use Fivenp\Identicon\Identicon; $options = array( 'size'=>2048, // a value between 16 and 2048 is accepted 'backgroundColor'=>array( // must be in red/green/blue "red" => "255", "green" => "255", "blue" => "255", ), ); $identicon = new Identicon(md5('TEST'),$options); $icon = $identicon->create();
You can also overwrite some more advanced settings, (*7)
<?php use Fivenp\Identicon\Identicon; $options = array( 'size'=>2048, // a value between 16 and 2048 is accepted ); $identicon = new Identicon(md5('TEST'),$options); // A cusom color palette where the generator is using the colors randomly from $identicon->palette = array( 'orange' => '#ff944e', 'red' => '#e84c3d', 'blue' => '#3598db', 'black' => '#000000', 'white' => '#ffffff', ); // A cusom color palette where the generator is using the backgroundColor randomly from $identicon->availableBackgroundColors = array( 'white', 'red', ); $icon = $identicon->create();
PHP-Identicons is distributed under the GPLv3 License., (*8)
This code was forked from Timo van Neerden project page on Github which was originnially created by Bong Costa in 2009., (*9)
It has been forked from its project page on SourceForge as I intend to enhance it a bit for personnal usage., (*10)