Jdenticon-net 1.0.2

Jdenticon .NET

Generates identicons as SVG or PNG files on the .NET Framework and .NET Standard platforms.

There is a newer version of this package available.
See the version list below for details.
Install-Package Jdenticon-net -Version 1.0.2
dotnet add package Jdenticon-net --version 1.0.2
paket add Jdenticon-net --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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 .NET Framework 2.x, 3.x, 4.x, .NET Standard 1.x and .NET Core 1.x.
  • 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://dmester.github.io/jdenticon-net-docs/.

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.Saturation (default 0.5)

    Saturation of colored 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
{
    Padding = 0.10f,
    BackColor = Color.Transparent,
    Saturation = 0.4f,
    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");

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 zlib license.

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 .NET Framework 2.x, 3.x, 4.x, .NET Standard 1.x and .NET Core 1.x.
  • 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://dmester.github.io/jdenticon-net-docs/.

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.Saturation (default 0.5)

    Saturation of colored 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
{
    Padding = 0.10f,
    BackColor = Color.Transparent,
    Saturation = 0.4f,
    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");

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 zlib license.

Version History

Version Downloads Last updated
2.2.0 418 7/23/2018
2.1.0 3,515 4/15/2018
2.0.0 174 3/14/2018
1.0.2 113 3/7/2018
1.0.1 1,752 7/5/2017
1.0.0 207 7/4/2017
0.9.0 355 8/20/2016