> npm i wa-sticker-formatter
Wa-Sticker-Formatter provides two ways to create stickers. The paramers are the same for both.
First is the Buffer, SVG String, URL or File path of static image, GIF or Video. The second is the options. GIFs and Videos will output an animated WebP file.
Sticker options are:
pack
- The pack name.
author
- The author name.
type
- Value from StickeTypes enum (exported). Can be 'crop' or 'full' or undefined (default).
categories
- The sticker category. Can be an array of Emojis or undefined (default).
quality
- The quality of the output file. Can be an integer from 0 to 100. Defaults to 100.
id
- The sticker id. If this property is not defined, it will be generated.
background
- Background color in hexadecimal format or an RGBA Object. Defaults to undefined (transparent).
Before using the library, you need to import it.
import { Sticker, createSticker, StickerTypes } from 'wa-sticker-formatter' // ES6
// const { Sticker, createSticker, StickerTypes } = require('wa-sticker-formatter') // CommonJS
const sticker = new Sticker(image, {
pack: 'My Pack', // The pack name
author: 'Me', // The author name
type: StickerTypes.FULL, // The sticker type
categories: ['๐คฉ', '๐'], // The sticker category
id: '12345', // The sticker id
quality: 50, // The quality of the output file
background: '#000000' // The sticker background color (only for full stickers)
})
const buffer = await sticker.toBuffer() // convert to buffer
// or save to file
await sticker.toFile('sticker.webp')
You can also chain methods like this:
const sticker = new Sticker(image)
.setPack('My Pack')
.setAuthor('Me')
.setType(StickerTypes.FULL)
.setCategories(['๐คฉ', '๐'])
.setId('12345')
.setBackground('#000000')
.setQuality(50)
.toBuffer()
The image
(first parameter) can be a Buffer, URL or File path.
const buffer = await createSticker(buffer, options) // same params as the constructor
// NOTE: `createSticker` returns a Promise of a Buffer
The following options are valid:
interface IStickerConfig {
/** Sticker Pack title*/
pack?: string
/** Sticker Pack Author*/
author?: string
/** Sticker Pack ID*/
id?: string
/** Sticker Category*/
categories?: Categories[]
/** Background */
background?: Sharp.Color
/** Sticker Type */
type?: StickerTypes | string
/* Output quality */
quality?: number
}
Sticker types are exported as an enum.
enum StickerTypes {
DEFAULT = 'default',
CROPPED = 'crop',
FULL = 'full'
}
Background can be a hex color string or a sharp color object.
{
"background": "#FFFFFF"
}
or
{
"background": {
"r": 255,
"g": 255,
"b": 255,
"alpha": 1
}
}
Here's some basic information about WhatsApp Sticker Metadata.
In WhatsApp, stickers have their own metadata embedded in the WebP file as They hold info like the author, the title or pack name and the category.
The text on bold is the pack title and the rest is the author. This is actually Exif Metadata embedded in the WebP file.
This is an array of Emojis. Learn More
Thanks for using Wa-Sticker-Formatter!