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!

See Get started or the documentation for more examples.

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

See Get started or the documentation for more examples.

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.

ASP.NET Core

Install the Jdenticon.AspNetCore NuGet package.

PM> Install-Package Jdenticon.AspNetCore

Call UseJdenticon in your Startup.cs. Put the call right above UseStaticFiles.

using Jdenticon.AspNetCore;
/* ... */

public class Startup
{
    /* ... */

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        /* ... */
        app.UseJdenticon();
        app.UseStaticFiles();
        app.UseMvc();
        /* ... */
    }
}

Add the following lines to your _ViewImports.cshtml.

@using Jdenticon.AspNetCore
@addTagHelper "*, Jdenticon.AspNetCore"

Render icons on a page by using any of the following examples:

@{
    var myIconValue = "jdenticon";
}

Icon: <img identicon-value="myIconValue" width="100" height="100" alt="Identicon" />
Icon: @Html.Identicon(myIconValue, size: 100, alt: "Icon")
Icon: <img src="@Url.Identicon(myIconValue, size: 100)" alt="Icon" width="100" height="100" />

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>

See Get started or the documentation for more examples.

.NET general usage

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.

Supported platforms

Browser client-sideVersion
Chrome7+
Safari5+
Internet Explorer9+
Firefox4+
Microsoft Edge1+
Opera11+
Web appsVersion
PHP5.3+
ASP.NET Core1.0+
ASP.NET MVC4.0+
ASP.NET WebApi4.0+
ASP.NET WebForms2.0+
General frameworkVersion
Node.js6.4.0+
.NET Framework2.0+
.NET Core1.0+
Windows Forms (GDI+)4.0+
WPF4.0+

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.