Identicon generator for PHP
, (*1)
Identicon is a library which generate an identicon image based on a string., (*2)
Here is some examples of awesome results!, (*3)
, (*4)
Installation
The recommended way to install Identicon is through composer., (*5)
Just add the library to your project:, (*6)
``` bash
composer require yzalis/identicon, (*7)
## Usage
Images are generated in PNG format with transparent background.
The string can be an email, an IP address, a username, an ID or something else.
### Generate an identicon
Create a new ```Identicon``` object.
``` php
$identicon = new \Identicon\Identicon();
Then you can generate and display an identicon image, (*8)
``` php
$identicon->displayImage('foo');, (*9)
or generate and get the image data
``` php
$imageData = $identicon->getImageData('bar');
or generate and get the base 64 image uri ready for integrate into an HTML img tag., (*10)
``` php
$imageDataUri = $identicon->getImageDataUri('bar');, (*11)
``` html
<img src="<?php echo $imageDataUri; ?>" alt="bar Identicon" />
Change the size
By default the size will be 64 pixels. If you want to change the image size just add a secondary parameter. 512 x 512px in this example., (*12)
``` php
$identicon->displayImage('foo', 512);, (*13)
### Color
The color is automatically generated according to the string hash but you can chose to specify a color by adding a third argument.
Color can be an hexadecimal with 6 characters
``` php
$identicon->displayImage('bar', 64, 'A87EDF');
or an array with red, green, blue value, (*14)
``` php
$identicon->displayImage('foo', 64, array(200, 100, 150));, (*15)
That's it!
### Generate an identicon on SVG format
The only thing you need to change it this one:
``` php
$identicon = new \Identicon\Identicon(new SvgGenerator());
$imageDataUri = $identicon->getImageDataUri('bar');
<img src="<?= $imageDataUri; ?>" alt="bar Identicon" />
Unit Tests
To run unit tests, you'll need and a set of dependencies you can install using Composer:, (*16)
php composer.phar install
Once installed, just launch the following command:, (*17)
./vendor/bin/phpunit
Everything should be ok., (*18)
Credits
Inspired by Github blog post about Identicon., (*19)
License
Identicon is released under the MIT License. See the bundled LICENSE file for details., (*20)