{identicon}

Draws a GitHub-style identicon as inline SVG - a symmetric 5 by 5 pattern and a colour from a hash of the value.

Pictures and media Single tags

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.

Templateexamples/identicon/1-accounts.pad
<table>
  {accounts}
  <tr><td>{identicon $email, size=40}</td><td>{$email}</td></tr>
  {/accounts}
</table>
PHPexamples/identicon/1-accounts.php
<?php

  $accounts = [
    [ 'email' => 'herbert@example.com' ],
    [ 'email' => 'ada@example.org'     ],
    [ 'email' => 'grace@example.net'   ],
    [ 'email' => ' Ada@Example.ORG '   ] ];

?>
Resultopen alone
Identicon herbert@example.com
Identicon ada@example.org
Identicon grace@example.net
Identicon Ada@Example.ORG

A wall of identicons

Ten user ids, ten patterns - title= names each for a screen reader.

Templateexamples/identicon/2-grid.pad
<div style="display:flex; flex-wrap:wrap; gap:10px">
  {sequence '1..10', name='id'}{identicon 'user-' . $id, size=48, title='User ' . $id}{/sequence}
</div>
Resultopen alone
User 1 User 2 User 3 User 4 User 5 User 6 User 7 User 8 User 9 User 10

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.