Jdenticon-net 2.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Jdenticon-net --version 2.1.0                
NuGet\Install-Package Jdenticon-net -Version 2.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Jdenticon-net" Version="2.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Jdenticon-net --version 2.1.0                
#r "nuget: Jdenticon-net, 2.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Jdenticon-net as a Cake Addin
#addin nuget:?package=Jdenticon-net&version=2.1.0

// Install Jdenticon-net as a Cake Tool
#tool nuget:?package=Jdenticon-net&version=2.1.0                

Jdenticon-net

.NET library for generating highly recognizable identicons.

Sample identicons

Features

Jdenticon-net is a .NET port of the JavaScript library Jdenticon.

  • Runs on multiple .NET platforms.
    • .NET Framework 2.0 and later
    • .NET Standard 1.0 and later
    • .NET Core 1.0 and later
  • Render icons as PNG and SVG files with no dependencies to System.Drawing or WPF.
  • Integration package available for ASP.NET WebForms, MVC and WebApi.
  • Generate SVG fragments to be used inline on websites.
  • Render icons directly on screen using GDI+.

Getting started

Using Jdenticon-net is simple. Follow the steps below to integrate Jdenticon-net into your solution.

1. Install the NuGet package

PM> Install-Package Jdenticon-net

2. Use Identicon to generate icons

using Jdenticon;
----
var icon = Identicon.FromValue("john.doe@example.faux", size: 100);
icon.SaveAsPng("johndoe.png");

ASP.NET

To get started using Jdenticon for ASP.NET, please see:

Quick Reference

For full documentation, please see https://jdenticon.com/net-api/.

Create an instance of Identicon

There are mainly two ways of creating an instance of Identicon:

  • Identicon.FromHash(hash, size)

    Creates an instance with a hash value. You can either provide a byte array containing the hash, or provide a hexadecimal hash string. At least 6 bytes are required in byte arrays and 12 characters in hash strings.

  • Identicon.FromValue(value, size[, hashAlgorithmName])

    Jdenticon-net will create a hash for you using the specified hash algorithm. You can provide any object, even null, as argument. Jdenticon will use ToString to get a string representation of the object and then push the UTF8-encoded string through the specified hash algorithm. If no hash algorithm is specified Jdenticon-net will default to SHA1.

Generate an icon

There are multiple methods in the Identicon class for generating icons:

  • SaveAsPng(path|stream)

    Generates an icon and saves it as a PNG image.

  • SaveAsSvg(path|stream|TextWriter)

    Generates an icon and saves it as an SVG image.

  • Draw(graphics, rectangle)

    Generates an icon and draws it in the specified GDI+ drawing context. Suitable if you want to display the icon on the screen without first saving it to a file.

  • ToBitmap()

    Generates an icon as a Bitmap object for later usage. Remember that you are responsible for disposing the returned object when you don't need it anymore.

  • ToSvg([fragment])

    Generates an SVG string containing an icon. This can be useful for embedding icons in other SVG files or inlining SVG icons on your website. For creating SVG files, please use Save.

Change icon appearance

There are properties on Identicon that can be used to customize the look of the generated icons.

  • Style.Padding (default 0.08)

    The padding between the outer bounds of the icon and the content. Specified as percent in the range [0.0, 0.4].

  • Style.BackColor (default white)

    Specifies the background color of the generated icon. Set to Color.Transparent to not render any background behind the identicon shapes.

  • Style.Hues (default empty, meaning no hue limit)

    By default a hue is selected for each individual hash. This property is used to limit the allowed hues. When this collection is not empty, the icon hues will be limited to the ones specified in the collection.

  • Style.ColorSaturation (default 0.5)

    Saturation of the originally colored shapes in the range [0.0, 1.0].

  • Style.GrayscaleSaturation (default 0.0)

    Saturation of the originally grayscale shapes in the range [0.0, 1.0].

  • Style.ColorLightness (default [0.4, 0.8])

    Lightness range of colored shapes in the range [0.0, 1.0]. The lightness of the shapes can be inverted by specifying a range where Range.From is greater than Range.To.

  • Style.GrayscaleLightness (default [0.3, 0.9])

    Lightness range of grayscale shapes in the range [0.0, 1.0]. The lightness of the shapes can be inverted by specifying a range where Range.From is greater than Range.To.

Example

using Jdenticon;
using Jdenticon.Rendering;
----
var iconStyle = new IdenticonStyle
{
    Hues = new HueCollection { { 314f, HueUnit.Degrees } },
    Padding = 0.10f,
    BackColor = Color.Transparent,
    ColorSaturation = 0.4f,
    GrayscaleSaturation = 0f,
    ColorLightness = Range.Create(0.4f, 0.9f),
    GrayscaleLightness = Range.Create(0.3f, 0.9f)
};

var icon = Identicon.FromValue("john.doe@example.faux", size: 100);
icon.Style = iconStyle;
icon.SaveAsPng("johndoe.png");

It is also possible to set a default style. In ASP.NET this can be done in Application_Start in your Global.asax file.

using Jdenticon;
using Jdenticon.Rendering;
----
Identicon.DefaultStyle = new IdenticonStyle
{
    Hues = new HueCollection { { 314f, HueUnit.Degrees } },
    Padding = 0.10f,
    BackColor = Color.Transparent,
    ColorSaturation = 0.4f,
    GrayscaleSaturation = 0f,
    ColorLightness = Range.Create(0.4f, 0.9f),
    GrayscaleLightness = Range.Create(0.3f, 0.9f)
};

var icon = Identicon.FromValue("john.doe@example.faux", size: 100);
icon.SaveAsPng("johndoe.png");

Advanced customizations

By subclassing Jdenticon.IconGenerator you can completely override the look of your icons. Set the Identicon.IconGenerator property to an instance of your own generator to make use of the customized icon generator.

License

Jdenticon-net is released under the MIT license.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.0 is compatible.  netstandard1.1 was computed.  netstandard1.2 was computed.  netstandard1.3 is compatible.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 was computed.  netstandard2.1 was computed. 
.NET Framework net20 is compatible.  net35 is compatible.  net40 is compatible.  net403 was computed.  net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 was computed. 
Windows Phone wp8 was computed.  wp81 was computed.  wpa81 was computed. 
Windows Store netcore was computed.  netcore45 was computed.  netcore451 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (8)

Showing the top 5 NuGet packages that depend on Jdenticon-net:

Package Downloads
Jdenticon.AspNetCore

Extends Jdenticon-net with features to use Jdenticon with ASP.NET Core. This package contains: * IdenticonTagHelper * @Html.Identicon() extension method * @Url.Identicon() extension method * IdenticonResult for usage in MVC controllers

Jdenticon.Gdi

This is a dependency to Jdenticon.WinForms. You probably want to install the Jdenticon.WinForms package instead. This package can on its own be used to: * Render identicons to System.Drawing.Graphics * Render identicons to System.Drawing.Bitmap * Render EMF (Enhanced Metafile) identicons This package is not intended for server-side applications.

Jdenticon.AspNet.Mvc

Extends Jdenticon-net with features to use Jdenticon with ASP.NET MVC. This package contains: * @Html.Identicon() extension method * @Url.Identicon() extension method * IdenticonResult for usage in MVC controllers

Jdenticon.AspNet.WebApi

Extends Jdenticon-net with features to use Jdenticon with ASP.NET WebApi. This package contains: * IdenticonResult for usage in WebApi controllers

Jdenticon.Wpf

Extends Jdenticon-net with features to use Jdenticon with WPF.

GitHub repositories (3)

Showing the top 3 popular GitHub repositories that depend on Jdenticon-net:

Repository Stars
IoTSharp/IoTSharp
IoTSharp is an open-source IoT platform for data collection, processing, visualization, and device management.
EverestAPI/Everest
Everest - Celeste Mod Loader / Mod API
LukeEmmet/GemiNaut
GemiNaut - A friendly Gemini client for Windows
Version Downloads Last updated
3.1.2 133,923 4/3/2021
3.1.1 8,075 1/22/2021
3.1.0 6,614 1/5/2021
3.0.0 2,447 1/1/2021
2.2.1 62,410 12/2/2018
2.2.0 52,984 7/23/2018
2.1.0 22,853 4/15/2018
2.0.0 3,479 3/14/2018
1.0.2 2,237 3/7/2018
1.0.1 4,393 7/5/2017
1.0.0 2,256 7/4/2017
0.9.0 1,476 8/20/2016