Entry class for rendering identicons.
__constructor | Creates a new Identicon . Optionally an associative array containing identicon options can be passed to the constructor. | |
draw | Draws this icon using a specified renderer. | |
displayImage | Renders the icon directly to the page output. | |
getImageData | Renders the icon and returns the icon data as a binary string. | |
getImageDataUri | Renders 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.
Property | Type | Description | |
---|---|---|---|
| hash | string | A 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. |
| value | mixed | The 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. |
| size | numeric | Sets 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. |
| style | Jdenticon\IdenticonStyle | array | Containing 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. |
| iconGenerator | Jdenticon\Rendering\IconGenerator | An 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. |
| enableImageMagick | bool | If If Default is |
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');