JSPM

  • Created
  • Published
  • Downloads 9741
  • Score
    100M100P100Q133983F
  • License MIT

SVG Converter for DiceBear

Package Exports

  • @dicebear/converter

Readme

DiceBear Converter

Converts DiceBear avatars (or any SVG) to raster formats: PNG, JPEG, WebP and AVIF. Works in Node.js and modern browsers.

Playground | Documentation

Installation

npm install @dicebear/converter

Requires Node.js 22+ or any modern browser.

Usage

import { Avatar } from '@dicebear/core';
import { toPng } from '@dicebear/converter';

// From a style definition (here from the @dicebear/styles package)
import definition from '@dicebear/styles/lorelei.json' with { type: 'json' };

const avatar = new Avatar(definition, { seed: 'John Doe' });

const png = toPng(avatar, { size: 256 });

await png.toDataUri(); // data:image/png;base64,...
await png.toArrayBuffer(); // ArrayBuffer

toJpeg, toWebp and toAvif work the same way. Each function also accepts a raw SVG string instead of an Avatar.

Sponsors

Advertisement: Many thanks to our sponsors who provide us with free or discounted products.

bunny.net