Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DannyAkintunde/wa-sticker-toolkit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

package logo

WA Sticker Toolkit

NPM CodeFactor NPM

Installation

Install via npm:

npm i wa-sticker-toolkit

Overview

wa-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.

Importing the Library

const {
    Sticker,
    createSticker,
    StickerTypes,
    TextPositions
} = require("wa-sticker-toolkit");
// ES6 import { Sticker, createSticker, StickerTypes, TextPositions } from "wa-sticker-toolkit";

Creating Stickers

There are two main ways to create stickers:

  1. 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.


  1. Using createSticker Function

    const buffer = await createSticker(image, options);
    // Returns a Promise that resolves to a Buffer

Options

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'
    }
}

Sticker Types & Text Positions

Sticker Types

const StickerTypes = Object.freeze({
    DEFAULT: "default",
    CROPPED: "crop",
    FILL: "fill",
    CIRCLE: "circle"
});

Text Positions

const TextPositions = Object.freeze({
    TOP: "top",
    CENTER: "center",
    BOTTOM: "bottom"
});

Background Options

You can specify a background color in two ways:

Hex Color String:

{ "background": "#FFFFFF" }

Sharp Color Object:

{
    "background": {
        "r": 255,
        "g": 255,
        "b": 255,
        "alpha": 1
    }
}

Note: The text color only accepts hex codes.


Configuration

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 Object

If not set, the toolkit assumes ffmpeg and ffprobe are available in your system's PATH.


WhatsApp Sticker Metadata

WhatsApp stickers include metadata such as the pack name, author, and categories.

  1. Author & Pack Title

    Metadata example

    Bold text: Pack title

    Remaining text: Author name

    This metadata is stored using Exif data embedded in the WebP file.

  2. Sticker Categories

    WhatsApp allows stickers to have emoji-based categories. Learn more.


Backward Compatibility

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.