npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@aboveyou00/identicon

v0.0.11

Published

Create indenticon-like visual hashes styled like Github and Gravatar (retro) avatars

Downloads

32

Readme

node-identicon-github

Dependency Status

The author of https://github.com/sehrgut/node-retricon has not maintain module for a long time (since 2013). Some dependencies has been updated and we need to use it.

Create indenticon-like image hashes styled like Github and Gravatar (retro) avatars

avatar avatar avatar avatar avatar avatar skull frog

Example

var identicon = require('identicon-github');
var fmt = require('util').format;

console.log(fmt("<img alt='kibo' src='%s' />", identicon('kibo', { pixelSize: 16 }).toDataURL()));

Output

<img alt='kibo' src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAYAAACOEfKtAAAABmJLR0QA/wD/AP+gvaeTAAAA7UlEQVR4nO3asQ3CQBAAwX9kiVqogP5DV0AtRFDEBCfDTm6/vbrodfv5un/WoPPx3vL89PffJg//BQVEBUQFRAVEBUQFRAVEBUQFRAVEBUQFRAVEBUR7+j7t6ppAVEBUQFRAVEBUQFRAVEBUQFRAVEBUQFRAVEBUQES7eWv5ft70fqCe3wSiAqICogKiAqICogKiAqICogKiAqICogKiAqICouPf9wP1/5tAVEBUQFRAVEBUQFRAVEBUQFRAVEBUQFRAVEBUQHToC66+39d94LACogKiAqICogKiAqICogKiAqICogKiAqICogKiL2SGHPJ+jTmVAAAAAElFTkSuQmCC' />

kibo

API

identicon(str, pixelSize, border)

  • str: string - username, email, or other string to hash
  • opts: object
    • pixelSize: int (default: 10) - width and height in pixels to render each tile
    • bgColor: mixed (default: null) - color to fill background
      • null for transparent
      • 0 or 1 for first (brighter) or second (darker) random color
      • CSS hex colorspec (e.g. '#F0F0F0')
    • pixelPadding: int (default: 0) - background pixels within the border of each rendered tile. Use negative values for overlap, as in Github- style identicons
    • imagePadding: int (default: 0) - padding around outside of image
    • tiles: int (default: 5) - number of tiles wide and high to render
    • minFill: float (default: 0.3) - proportion of tiles which must be filled. Hash chaining is used to satisfy fill criteria.
    • maxFill: float (default: 0.9) - maximum proportion of tiles which may be filled.
    • pixelColor: mixed (default: 0) - color to fill foreground tiles. All bgColor values are valid for pixelColor.

Returns a Canvas object containing the rendered image.

Styles

All style options can be changed, but identicon comes with several prerolled styles:

default

Coloured tiles against a transparent background.

default

mini

Tiny 3x3 identicons with padded tiles.

mini

gravatar

Not a perfect replica of Gravatar's "retro" style, but close.

gravatar

mono

Black tiles on a grey background.

mono

mosaic

Padded tiles, for a mosaic effect.

mosaic

window

Transparent, padded tiles against coloured background.

window

github

Faithful replica of Github's identicon style.

github

custom example

Absurd settings, such as: { pixelSize: 8, pixelPadding: -2, tiles: 30, pixelColor: 0, bgColor: 1 } can still yield quite serviceable results.

bat

Algorithm

The input string is converted to a buffer of UTF-8 bytes. A one-byte iterator is appended to this, initialized at zero, for hash chaining. The buffer is passed through SHA-512, and the output buffer is iteratively XORed to produce a final buffer of only the number of required bytes (currently eighteen). The first six bytes are taken as RGB values for the colours. The remaining bytes are quantized to boolean values at a threshold of 127. If a minimum proportion of the booleans are true, but not more than the maximum proportion, the hash is accepted. Otherwise, the iterator is incremented, and the process repeated.

The array of booleans is taken to be a row-major array covering the left half of the final image. It is reflected about the central vertical axis (or column, for odd-order arrays) which is then rendered as the final visual hash.

Known Limitations

  • 30x30 tile images are the maximum which can be generated from SHA-512.