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.
Installation
npm install @dicebear/converterRequires 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(); // ArrayBuffertoJpeg, 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.