Install via npm:
npm i wa-sticker-toolkitwa-sticker-toolkit provides a simple way to create WhatsApp stickers from various sources such as Buffers, URLs, SVG strings, Base64-encoded images, file paths, GIFs, and videos. The output format is WebP, with GIFs and videos automatically converted into animated stickers.
const {
Sticker,
createSticker,
StickerTypes,
TextPositions
} = require("wa-sticker-toolkit");
// ES6 import { Sticker, createSticker, StickerTypes, TextPositions } from "wa-sticker-toolkit";There are two main ways to create stickers:
-
Using the Sticker Constructor (Recommended)
const sticker = new Sticker(image, { metadata: { pack: "My Pack", // Pack name author: "Me", // Author name id: "12345", // Sticker ID (auto-generated if omitted) categories: ["🤩", "🎉"] // Used for WhatsApp sticker search }, type: StickerTypes.FILL, // Sticker type quality: 50, // Output quality (1-100) background: "#000000" // Background color }); // Convert to buffer const buffer = await sticker.toBuffer(); // Save to file await sticker.toFile("sticker.webp"); // Send using Baileys-MD conn.sendMessage(jid, await sticker.toMessage());
You can also chain methods for better readability:
const buffer = await new Sticker(image) .setPack("My Pack") .setAuthor("Me") .setType(StickerTypes.FILL) .setCategories(["🤩", "🎉"]) .setId("12345") .setBackground("#000000") .setQuality(50) .toBuffer();
Note: The image parameter can be a Buffer, URL, SVG string, Base64 string, or file path.
-
Using createSticker Function
const buffer = await createSticker(image, options); // Returns a Promise that resolves to a Buffer
The second parameter (options) is an object that allows customization:
{
metadata: {
pack: "Pack Name",
author: "Author Name",
id: "Sticker ID",
categories: ["🤣", "❤️"]
},
type: StickerTypes.FILL, // 'default', 'crop', 'fill', 'circle'
quality: 80, // Integer (1-100)
background: "#FFFFFF", // Hex color or sharp color object
borderWidth: 5, // Border width (default: 0)
borderColor: "#FF0000", // Border color (default: white)
borderRadius: "50%", // Rounded corners (percentage or integer)
text: {
content: "Hello!", // Text overlay
color: "#FFFFFF", // Text color (hex only)
font: "Arial", // Font family
fontSize: 24, // Font size
position: TextPositions.BOTTOM // 'top', 'center', 'bottom'
}
}const StickerTypes = Object.freeze({
DEFAULT: "default",
CROPPED: "crop",
FILL: "fill",
CIRCLE: "circle"
});const TextPositions = Object.freeze({
TOP: "top",
CENTER: "center",
BOTTOM: "bottom"
});You can specify a background color in two ways:
{ "background": "#FFFFFF" }{
"background": {
"r": 255,
"g": 255,
"b": 255,
"alpha": 1
}
}Note: The text color only accepts hex codes.
You can set custom paths for ffmpeg and ffprobe using the config system:
const { config } = require("wa-sticker-toolkit");
config.setConfig({
ffmpegPath: "/custom/path/to/ffmpeg",
ffprobePath: "/custom/path/to/ffprobe"
});
// use config.getConfig() to get config ObjectIf not set, the toolkit assumes ffmpeg and ffprobe are available in your system's PATH.
WhatsApp stickers include metadata such as the pack name, author, and categories.
-
Author & Pack Title
Bold text: Pack title
Remaining text: Author name
This metadata is stored using Exif data embedded in the WebP file.
-
Sticker Categories
WhatsApp allows stickers to have emoji-based categories. Learn more.
If you're migrating from wa-sticker-formatter or @shibam/sticker-maker, no major changes are needed—just update your import statements, and everything should work seamlessly.
Thanks for using wa-sticker-toolkit!
This program is licensed under the MIT license.