Skip to content

maartenkeizer/dither-avatar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dither-avatar

Deterministic dithered SVG avatars from any seed string. Zero dependencies.

preview

Live playground →

Install

npm install dither-avatar

Usage

Core (any JS runtime)

import { generateDitherAvatar, ditherAvatarDataUri } from 'dither-avatar';

const svg = generateDitherAvatar('alice');
const uri = ditherAvatarDataUri('alice');

React

import { DitherAvatar } from 'dither-avatar/react';

function UserProfile({ username }) {
  return <DitherAvatar seed={username} size={48} />;
}

API

generateDitherAvatar(seed: string): string

Returns raw SVG markup for the given seed.

ditherAvatarDataUri(seed: string): string

Returns a data:image/svg+xml,... URI — safe to use as an <img> src.

<DitherAvatar seed size? className? style? />

Renders an <img> with the avatar as a data URI. Zero XSS risk.

<DitherAvatarSVG seed size? className? style? />

Renders an inline <svg>. Note: uses dangerouslySetInnerHTML.

License

MIT

About

Deterministic dithered SVG avatars from any seed string. Zero dependencies.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors