@dicebear/converter
v11.0.0
Published
SVG Converter for DiceBear
Readme
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/converter @dicebear/core @dicebear/stylesThe converter takes the SVG that @dicebear/core renders.
Requires Node.js 22+ or any modern browser.
Usage
import { Avatar, Style } 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(new Style(definition), { seed: 'John' });
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.
