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')
Choose a style
Set style to any slug from the style list.
const svg = palletface('user-123', { style: 'dither-orb' })
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 }),
)
24 px
40 px
64 px
96 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 }),
)
Ada
Élodie
42
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
pixel-letter
dither-orb
pixel-landscape
pixelify-letter
geometric-tile
random-contours
pixel-emotes
mirrored-signal
pixel-flora
pixel-relic
pixel-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' }),
)
ada
kai
yuki
noor
tomás
mina
To show an SVG in a page or return it from a server, see Integrations.