All Projects → laurentpayot → minidenticons

laurentpayot / minidenticons

Licence: MIT license
Super lightweight SVG identicon (icon avatar) generator

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to minidenticons

identicon-api
A simple API to retrieve SVG identicons
Stars: ✭ 15 (-83.15%)
Mutual labels:  identicon, avatar, avatar-generator, identicon-generator
BlockiesSwift
Unique blocky identicons generator for Swift
Stars: ✭ 53 (-40.45%)
Mutual labels:  identicon, identicon-generator, identicon-avatar
identicon
Original Identicon java and canvas implementations
Stars: ✭ 64 (-28.09%)
Mutual labels:  identicon, identicon-library, identicon-generator
monsterID
The original MonsterID implementation
Stars: ✭ 56 (-37.08%)
Mutual labels:  identicon, avatar, avatar-generator
identicon-avatar
👾 GitHub style identicon avatar
Stars: ✭ 15 (-83.15%)
Mutual labels:  identicon, avatar, identicon-avatar
icodi
Deterministic Random SVG Icon Generator
Stars: ✭ 18 (-79.78%)
Mutual labels:  identicon, avatar-generator, identicon-generator
flagpack
A lightweight flag icon toolkit for the web.
Stars: ✭ 51 (-42.7%)
Mutual labels:  lightweight, svg-icons
tiny-framework
A light wight easy to use RESTful apis framework for education & demo purposes. stripped down framework to the fundamental components that that every one would essentially need to (learn / make a demo application).
Stars: ✭ 13 (-85.39%)
Mutual labels:  lightweight, tiny
Spruce
A lightweight state management layer for Alpine.js. 🌲
Stars: ✭ 720 (+708.99%)
Mutual labels:  lightweight, tiny
TTInputVisibilityController
Lightweight controller to keep your inputs visible when the keyboard is presented.
Stars: ✭ 21 (-76.4%)
Mutual labels:  light, lightweight
go-qidenticon
qidenticon (identicon generator from Bitmessage) ported to Go
Stars: ✭ 12 (-86.52%)
Mutual labels:  identicon, identicon-generator
MatrixLib
Lightweight header-only matrix library (C++) for numerical optimization and machine learning. Contact me if there is an exciting opportunity.
Stars: ✭ 35 (-60.67%)
Mutual labels:  light, lightweight
Utox
µTox the lightest and fluffiest Tox client
Stars: ✭ 820 (+821.35%)
Mutual labels:  light, lightweight
Gravatar
👤 Gravatar Helper & Generator (Laravel supported)
Stars: ✭ 19 (-78.65%)
Mutual labels:  identicon, avatar
Bytesize Icons
Tiny style-controlled SVG iconset (101 icons, 12kb)
Stars: ✭ 3,662 (+4014.61%)
Mutual labels:  lightweight, svg-icons
awesome-identicons
A curated list of "Visual Hashs" (Identicon, Avatar, Fractal, RandomArt and general Hash Visualization)
Stars: ✭ 156 (+75.28%)
Mutual labels:  identicon, avatar
Translucide
CMS efficient, léger, simple à prendre en main, customisable et écoconçu !
Stars: ✭ 31 (-65.17%)
Mutual labels:  light, lightweight
avatarcropper
Simple quick avatar cropper!
Stars: ✭ 45 (-49.44%)
Mutual labels:  avatar, avatar-generator
pixitar
🧝 Pixitar is an avatar generation library written in Ruby.
Stars: ✭ 20 (-77.53%)
Mutual labels:  avatar, avatar-generator
Axel
Axel tries to accelerate the download process by using multiple connections per file, and can also balance the load between different servers.
Stars: ✭ 1,997 (+2143.82%)
Mutual labels:  light, lightweight

Minidenticons

Super lightweight SVG identicon generator. No dependencies.

minified + brotlied size minified + zipped size (using the custom element)

minified + brotlied size minified + zipped size (custom element tree-shaken)

dependencies types npm license

Minidenticons

Why

Generate identicons (pixelated avatars) on the client from usernames instead of fetching images from a server!

Live Demo 🎮

Play with it here.

On Browser

Minidenticons uses ES modules, now widely supported in browsers.

Using the identicon-svg custom element

Import the identicon-svg custom element from the minidenticons.min.js file. This file can be located in a CDN (example below) or copied in any directory of your website (for better performance, since you don’t have to connect to the CDN).

<script type="module">
  import { identiconSvg } from 'https://unpkg.com/[email protected]/minidenticons.min.js'
</script>

Then simply use identicon-svg tags with a username attribute 😂

<identicon-svg username="alienHead66">

For instance with the alienHead66 username you will get the following identicon (without the border):

alienHead66 identicon

Color Customization

By default the color saturation and lightness are set to 50%. But you can change these values with the saturation and/or lightness attributes, for instance:

<identicon-svg username="alienHead66" saturation="95" lightness="60">

Play with the demo to find a combination of saturation and lightness that matches your website theme colors: light, dark, pastel or whatever 😎

Minidenticons light Minidenticons dark Minidenticons pastel

Using the identicon function

Alternatively, instead of identiconSvg, you can also import the identicon function described in the NodeJS section below and use it to generate SVG strings in your browser.

On NodeJS

Be sure to use a NodeJS version greater or equal to 14.0.0.

Installation

npm install minidenticons

Import

import { identicon } from 'minidenticons'

The identicon-svg custom element should be tree-shaken from your bundle, for an even smaller size of minidenticons 😁

Usage

identicon(username: string, saturation?: number|string, lightness?: number|string): string

The identicon function will return a SVG string generated from its username string argument. The optional saturation and lightness arguments should be percentages; that is, numbers (or strings) between 0 and 100.

Framework integrations

React

Here are some CodePen examples on how to use Minidenticons as a React function component:

If you think of a different way to integrate Minidenticons into React feel free to comment this issue. Thanks!

Workbox

In this example using Workbox, identicons are generated by the service worker and cached for one year. They can be displayed and downloaded like normal images with a path ending with identicons/<username>.svg.

registerRoute(
  /identicons\/[^\/]+\.svg$/,
  async ({ url }) => {
    const username = url.pathname.match(/([^\/]+)\.svg$/)[1]
    return new Response(
      identicon(username),
      { headers: { "Content-Type": "image/svg+xml", "Cache-Control": "max-age=31536000" } }
    )
  }
)

Elm

For Elm enthusiasts there is a Minidenticons package on the Elm package repository: minidenticons-elm.

Collisions

You will always get the same identicon for a given username. But it is not impossible to have different usernames with the same identicon. That's a collision.

Generated identicons are 5×5 pixels large with vertical symmetry, and can have 18 different hues for the same saturation and lightness. This means there are 2(3×5) × 18 = 589,824 different identicons possible, but actually much less because of the modulo-based algorithm used to get more colored pixels at the center of the identicon instead of having them scattered. So duplicate identicons are inevitable when using a lot of them. It shouldn’t matter as identicons should not be used solely to identify an user, and should always be coupled to a unique username 😉

The npm test command results below show that you have roughly a 7% chance to generate a duplicate identicon when already using 1000 of them.

0 collisions out of 100 (0.00%)
0 collisions out of 200 (0.00%)
2 collisions out of 300 (0.67%)
6 collisions out of 400 (1.50%)
11 collisions out of 500 (2.20%)
21 collisions out of 600 (3.50%)
38 collisions out of 700 (5.43%)
49 collisions out of 800 (6.13%)
55 collisions out of 900 (6.11%)
66 collisions out of 1000 (6.60%)
296 collisions out of 2000 (14.80%)
589 collisions out of 3000 (19.63%)
962 collisions out of 4000 (24.05%)
1441 collisions out of 5000 (28.82%)
1965 collisions out of 6000 (32.75%)
2564 collisions out of 7000 (36.63%)
3173 collisions out of 8000 (39.66%)
3860 collisions out of 9000 (42.89%)
4570 collisions out of 10000 (45.70%)

Performance

Minidenticons are fast.

  • To see how long it takes for your browser to generate 300 identicons (for a big page) try out the online benchmark.

  • The same benchmark is available for NodeJS. Simply run node benchmark/node at the root of a Minidenticons git clone.

License

MIT

Stargazers ❤️

Stargazers repo roster for @laurentpayot/minidenticons

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].