palletface

Examples

Each snippet below runs when the docs are built, and the avatars under it are what it returns. To try your own seed, open the playground.

The snippets use this import:

import { palletface, STYLES } from 'palletface'

Default avatar

Pass only a seed to get pixel-sprite at 80 px.

const svg = palletface('user-123')
  • pixel-sprite avatar for “user-123”, 80 px

Choose a style

Set style to any slug from the style list.

const svg = palletface('user-123', { style: 'dither-orb' })
  • dither-orb avatar for “user-123”, 80 px

Set the size

px sets the width and height in CSS pixels.

const sizes = [24, 40, 64, 96]
const avatars = sizes.map((px) =>
  palletface('user-123', { style: 'pixel-landscape', px }),
)
  • pixel-landscape avatar for “user-123”, 24 px24 px
  • pixel-landscape avatar for “user-123”, 40 px40 px
  • pixel-landscape avatar for “user-123”, 64 px64 px
  • pixel-landscape avatar for “user-123”, 96 px96 px

Draw an initial

Initial styles draw the first letter or digit of name. Accents are dropped, so Élodie draws E. The seed still picks the colors, and without a name the style uses the seed.

const names = ['Ada', 'Élodie', '42']
const avatars = names.map((name) =>
  palletface('user-123', { style: 'pixel-letter', name }),
)
  • pixel-letter avatar for “user-123” named Ada, 80 pxAda
  • pixel-letter avatar for “user-123” named Élodie, 80 pxÉlodie
  • pixel-letter avatar for “user-123” named 42, 80 px42

Every style for one seed

Loop over STYLES to show every style in your installed version.

const avatars = STYLES.map(({ slug }) =>
  palletface('user-123', { style: slug, px: 64 }),
)
  • pixel-sprite avatar for “user-123”, 64 pxpixel-sprite
  • pixel-letter avatar for “user-123”, 64 pxpixel-letter
  • dither-orb avatar for “user-123”, 64 pxdither-orb
  • pixel-landscape avatar for “user-123”, 64 pxpixel-landscape
  • pixelify-letter avatar for “user-123”, 64 pxpixelify-letter
  • geometric-tile avatar for “user-123”, 64 pxgeometric-tile
  • random-contours avatar for “user-123”, 64 pxrandom-contours
  • pixel-emotes avatar for “user-123”, 64 pxpixel-emotes
  • mirrored-signal avatar for “user-123”, 64 pxmirrored-signal
  • pixel-flora avatar for “user-123”, 64 pxpixel-flora
  • pixel-relic avatar for “user-123”, 64 pxpixel-relic
  • pixel-stamp avatar for “user-123”, 64 pxpixel-stamp

One style for many users

Use a stable user ID as the seed. Each user keeps the same avatar every time it renders.

const users = ['ada', 'kai', 'yuki', 'noor', 'tomás', 'mina']
const avatars = users.map((id) =>
  palletface(id, { style: 'pixel-flora' }),
)
  • pixel-flora avatar for “ada”, 80 pxada
  • pixel-flora avatar for “kai”, 80 pxkai
  • pixel-flora avatar for “yuki”, 80 pxyuki
  • pixel-flora avatar for “noor”, 80 pxnoor
  • pixel-flora avatar for “tomás”, 80 pxtomás
  • pixel-flora avatar for “mina”, 80 pxmina

To show an SVG in a page or return it from a server, see Integrations.