{identicon}
Draws a GitHub-style identicon as inline SVG - a symmetric 5 by 5 pattern and a colour from a hash of the value.
Syntax
{identicon $email}
{identicon $value, size=64, title='text'}
Parameters
-
value - What the picture is made from - an e-mail address, a user id, a key. Trimmed and lower-cased before it is hashed.
Options
-
size - Width and height in pixels, default 64.
-
title -
The accessible name, default
Identicon- the value itself is not written into the page.
Description
{identicon} gives every account a picture of its own without asking for one: a symmetric pattern on a 5 by 5 grid and a colour, both taken from a SHA-256 hash of the value (tags/_lib/identicon.php). Nothing leaves the server, and the same value is always the same picture.
The value is trimmed and lower-cased before it is hashed, so every spelling of an e-mail address is one picture. Fifteen nibbles of the hash fill the left three columns, mirrored to the right; the colour is a hue from the last bytes at a saturation and lightness that read on the light square behind it, --pad-identicon-background on .pad-identicon (a light-dark() default, written once per page).
Unlike {avatar} the picture says nothing of the value: the accessible name is Identicon, or title, never the address itself. An empty value is an error under the strict check.
Examples
An identicon per account
The value is trimmed and lower-cased first - the last row is the second one spelled differently.
<table>
{accounts}
<tr><td>{identicon $email, size=40}</td><td>{$email}</td></tr>
{/accounts}
</table>
<?php
$accounts = [
[ 'email' => 'herbert@example.com' ],
[ 'email' => 'ada@example.org' ],
[ 'email' => 'grace@example.net' ],
[ 'email' => ' Ada@Example.ORG ' ] ];
?>
| herbert@example.com | |
| ada@example.org | |
| grace@example.net | |
| Ada@Example.ORG |
A wall of identicons
Ten user ids, ten patterns - title= names each for a screen reader.
<div style="display:flex; flex-wrap:wrap; gap:10px">
{sequence '1..10', name='id'}{identicon 'user-' . $id, size=48, title='User ' . $id}{/sequence}
</div>
See also
- {avatar} Draws an initials avatar as inline SVG - the letters of a name in a circle coloured by a hash of it, no image needed.
- {gravatar} Writes the Gravatar picture of an e-mail address as an img - only a hash of the address leaves the page - or a local avatar instead.