- πΌοΈ Supports static images, GIFs, and Videos (animated WebP output)
- π¨ Custom backgrounds, types, and categories
- π Fluent method chaining API
- π¦ Baileys-MD compatible output
- π Metadata extraction from existing stickers
- π Multiple sticker types: Default, Crop, Full, Circle, Rounded
- ποΈ SVG input support
npm i stickers-formatterimport { Sticker, StickerTypes } from 'stickers-formatter'
const sticker = new Sticker('./image.png', {
pack: 'My Pack',
author: 'Me',
type: StickerTypes.FULL,
})
const buffer = await sticker.toBuffer()import { Sticker, createSticker, StickerTypes } from 'stickers-formatter' // ES6
// const { Sticker, createSticker, StickerTypes } = require('stickers-formatter') // CommonJSStickers-Formatter provides two ways to create stickers β the Sticker class and the createSticker function. Both accept the same parameters:
| Parameter | Type | Description |
|---|---|---|
image |
Buffer | string |
Buffer, URL, SVG string, or file path. GIFs and videos produce animated WebP. |
options |
IStickerOptions |
Configuration object (see Options) |
const sticker = new Sticker(image, {
pack: 'My Pack',
author: 'Me',
type: StickerTypes.FULL,
categories: ['π€©', 'π'],
id: '12345',
quality: 50,
background: '#000000'
})
const buffer = await sticker.toBuffer()
await sticker.toFile('sticker.webp')
sock.sendMessage(jid, await sticker.toMessage())const buffer = await new Sticker(image)
.setPack('My Pack')
.setAuthor('Me')
.setType(StickerTypes.FULL)
.setCategories(['π€©', 'π'])
.setID('12345')
.setBackground('#000000')
.setQuality(50)
.toBuffer()const sticker = new Sticker(`
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512">
<path d="M256 0C114.6 0 0 114.6 0 256s114.6 256 256 256 256-114.6 256-256S397.4 0 256 0z" fill="#ff0000" />
</svg>
`, { author: 'Me', pack: 'SVG Pack' })const buffer = await createSticker(image, options)Returns a
Promise<Buffer>β useful for functional-style code.
interface IStickerOptions {
pack?: string
author?: string
id?: string
categories?: Categories[]
background?: Sharp.Color
type?: StickerTypes | string
quality?: number
}| Option | Type | Default | Description |
|---|---|---|---|
pack |
string |
'' |
Sticker pack title |
author |
string |
'' |
Sticker pack author |
id |
string |
auto-generated | Unique sticker pack ID |
categories |
string[] |
undefined |
Array of emojis for categorization |
background |
string | object |
transparent |
Hex string or RGBA object |
type |
StickerTypes |
DEFAULT |
How the image is fitted |
quality |
number (0β100) |
100 |
Output WebP quality |
enum StickerTypes {
DEFAULT = 'default',
CROPPED = 'crop',
FULL = 'full',
CIRCLE = 'circle',
ROUNDED = 'rounded'
}| Type | Description |
|---|---|
DEFAULT |
Standard WhatsApp sticker sizing |
CROPPED |
Crops the image to fit |
FULL |
Fits the full image with optional background |
CIRCLE |
Circular crop |
ROUNDED |
Rounded corners |
The background option accepts a hex string or a Sharp RGBA object.
background: '#FFFFFF'background: {
r: 255,
g: 255,
b: 255,
alpha: 1
}Background is only applied when using
StickerTypes.FULL.
WhatsApp stickers embed metadata (author, pack name, category) directly into the WebP file as Exif data.
Bold text = Pack title Β |Β Regular text = Author name
Categories are arrays of emojis embedded in the sticker metadata. Learn more β
import { extractMetadata, Sticker } from 'stickers-formatter'
import { readFileSync } from 'fs'
const file = readFileSync('sticker.webp')
const metadata = await extractMetadata(file)
// {
// emojis: [],
// 'sticker-pack-id': '',
// 'sticker-pack-name': '',
// 'sticker-pack-publisher': ''
// }
const metadata2 = await Sticker.extractMetadata(file)Contributions, issues and feature requests are welcome! Feel free to open an issue or submit a pull request.
Distributed under the MIT License. See LICENSE for more information.
Made with β€οΈ β Thanks for using Stickers-Formatter!