I’ve updated Daily with following identicon related changes:
Persistent identicon changes require some database changes so expect some delay on that.
My implementation of identicon is written in Java so you’ll have to port the code if you are not using java. If you are, it’s just a matter of hooking up the servlet, set inetSalt init-parameter, and you are ready to go.
Anyway, here is the preliminary (pre-cleanup/pre-documentation) version of Identicon source code. License is simply Go-Nuts-With-It. If and when later versions are released, it’s likely to adopt more formal license.
Documentation? You’ll have to make do with this single sentence version for now (sorry): IdenticonRenderer renders identicons, IdenticonUtil has code that derives identicon code from IP address.
Since non-java folks are starting to port the code before it can be properly documented, allow me to describe the rendering code to help them with their task.
How to draw an Identicon
A 9-block is a small quilt using only 3 types of patches, out of 16 available, in 9 positions. Using the identicon code, 3 patches are selected: one for center position, one for 4 sides, and one for 4 corners.
Positions and Rotations
For center position, only a symmetric patch is selected (patch 1, 5, 9, and 16). For corner and side positions, patch is rotated by 90 degree moving clock-wise starting from top-left position and top position respectively. This means 2 bits out of identicon code is used o select the center patch, 4 bits each for corner and side patches, 2 bits each for starting rotation of corner and side patches. In the source, each block array contains 4 rotated versions of each patch. You can do the same or generate the rotated versions on the fly.
Coloring and Inverting
I am using white background with a patch color selected using 15 bits from the identicon code, expending 5 bits for each color component (R, G, B) placed at high-end of the component value (bits << 3). 1 bit per patch is used for inversion, meaning selected color will be used as background and white used as the patch shape color. Note that patch 16 is just an inverted version of patch 1.
Adding it up, you are using 32 bits ((2 + 4 + 4 + 2 + 2) + (15 + 3)) to render an identicon.
While the shapes themselves can be rendered directly using anti-aliasing, I got better result from drawing a scaled up version then scaling down to requested size. Also it’s faster this way and works with graphics toolkits without anti-aliasing support.
Let me know if you have any questions. BTW, I am going to add more types of patches, symmetries, and quilts in the near future which will make wider variations of identicons. Wild!
Charles Darke has implemented a variation called Visiglyph using PHP.