Class Jdenticon\Identicon

Entry class for rendering identicons.


Method__constructorCreates a new Identicon. Optionally an associative array containing identicon options can be passed to the constructor.
MethoddrawDraws this icon using a specified renderer.
MethoddisplayImageRenders the icon directly to the page output.
MethodgetImageDataRenders the icon and returns the icon data as a binary string.
MethodgetImageDataUriRenders the icon and returns the icon as a data URI.


The following options are available to the Identicon class. The options can either be set using magic properties, or by passing the options in an associative array to the constructor or the setOptions method.

PropertyhashstringA binary string containing the hash that the icon will be generated from. The string must contain at least 6 bytes. This property is not needed if value is specified.
PropertyvaluemixedThe value will be converted to a UTF8 encoded string and then hashed using SHA1. The icon will be generated from this hash. This property is not needed if hash is specified.
PropertysizenumericSets the size of the icon in pixels. The size should be at least 1 pixel. Remember that large icons takes a lot of time to rasterize.
PropertystyleJdenticon\IdenticonStyle | arrayContaining styling options for this icon. When setting this option you can choose between specifying an Jdenticon\IdenticonStyle instance, or an associative array containing Jdenticon\IdenticonStyle options.
PropertyiconGeneratorJdenticon\Rendering\IconGeneratorAn icon generator creates shapes out of a hash and pass them on to a Jdenticon\Rendering\RendererInterface. If you want to customize what shapes are rendered in the icon, create a new class inheriting from IconGenerator and override the renderForeground and/or renderBackground methods.

If true is specified ImageMagick will be used to generate PNG icons. To use ImageMagick, ImageMagick must be installed and the Imagick PHP extension enabled.

If false is specified, an internal PNG renderer will be used for generating PNG icons. The internal renderer has no external dependencies, and is recommended for PHP 7 and later. For PHP 5, ImageMagick is recommended for better performance.

Default is true for PHP 5 with Imagick installed. In all other cases the default value is false.


The following example shows multiple ways how to set options of the Identicon class.


// Associative array to the constructor
$icon = new \Jdenticon\Identicon(array(
'size' => 50,
'value' => 'John Doe'

// Magic properties
$icon->size = 50;
$icon->value = 'John Doe';

// Public setters
$icon->setValue('John Doe');