Class Jdenticon\Identicon

Entry class for rendering identicons.

Methods

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.

Options

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.

PropertyTypeDescription
PropertyhashstringA binary string containing the hash that the icon will be generated from. The string must cotnain at least 6 bytes.
PropertyvaluemixedThe value will be converted to a UTF8 encoded string and then hashed using SHA1. The icon will be generated from this hash.
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.
PropertyenableImageMagickbool

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 on PHP 7 and later. On PHP 5 ImageMagick is recommended for better performance.

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

Examples

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

<?php
include_once("vendor/autoload.php");

// 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->setSize(50);
$icon->setValue('John Doe');