Jdenticon

Open source library for generating identicons.

A modern browser is needed to generate jdenticons.

Jdenticon

Open source library for generating identicons.

identicon

An Identicon is a visual representation of a hash value, usually of an IP address, that serves to identify a user of a computer system as a form of avatar while protecting the users' privacy.

Wikipedia

Quick start

In the browser

Include the Jdenticon library somewhere on your page. Jdenticon is served from jsDelivr in this example.

<script src="https://cdn.jsdelivr.net/npm/jdenticon@2.1.0" async>
</script>

Add an empty inline <svg> element where you want to render an identicon. Use the data-jdenticon-value attribute to specify that an identicon should be rendered. user127 below is just an example of a value.

<svg data-jdenticon-value="user127" width="80" height="80">
    Fallback text or image for browsers not supporting inline svg.
</svg>

Refresh the page and voila!

Node.js

Create an empty directory and install the Jdenticon NPM package.

> npm install jdenticon

Save the following code as test.js in the directory you created above.

var jdenticon = require("jdenticon"),
    fs = require("fs"),
    size = 200,
    value = "icon value",
    png = jdenticon.toPng(value, size);
    
fs.writeFileSync("./testicon.png", png);

Run the test file and open testicon.png in the working directory.

> node ./test.js

.NET command line

Install the Jdenticon-net NuGet package.

PM> Install-Package Jdenticon-net

Use the Identicon class to create identicons.

using Jdenticon;

class Program
{
    static void Main() 
    {
        Identicon
            .FromValue("string to hash", size: 160)
            .SaveAsPng("test.png");
    }
}

See Get started or the documentation for more examples.

ASP.NET MVC

Install the Jdenticon.AspNet.Mvc NuGet package.

PM> Install-Package Jdenticon.AspNet.Mvc

Now you can render icons on any page by using the following code:

@using Jdenticon.AspNet.Mvc;

<div>
    Icon: @Html.Identicon("Value to be hashed", size: 100, alt: "Icon")
    Icon: <img src="@Url.Identicon("Value to be hashed", size: 100)" alt="Icon" width="100" height="100" />
</div>

PHP

Install the Jdenticon Composer package.

$ composer require jdenticon/jdenticon

Use the Identicon class to create identicons.

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

$icon = new \Jdenticon\Identicon();
$icon->setValue('Value to be hashed');
$icon->setSize(100);
$icon->displayImage();

See Get started or the documentation for more examples.

Supported platforms

Chrome v7 and later
Firefox v4 and later
Opera 11 and later
Internet Explorer 9 and later
Microsoft Edge
Node.js
.NET Framework 2.0 and later
.NET Standard 1.0 and later
.NET Core 1.0 and later
  • Chrome v7 and later
  • Firefox v4 and later
  • Opera 11 and later
  • Internet Explorer 9 and later
  • Microsoft Edge
  • Node.js
  • .NET Framework 2.0 and later
  • .NET Standard 1.0 and later
  • .NET Core 1.0 and later

License

Jdenticon is released under the terms of the MIT license.

Copyright (c) 2014-2018 Daniel Mester Pirttijärvi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.