Skip to content

pystark.helpers.stickers

This module contains some sticker conversion tools for Telegram

to_webp(path) async

Convert any image to webp for telegram static stickers. Resizes according to telegram sticker requirements automatically.

Important

Requires library pillow which is not bundled with pystark.

Add pillow to your requirements.txt | pip install pillow

Parameters:

Name Type Description Default
path str

Path of image to convert to webp.

required

Returns:

Type Description
str

path to the converted webp image.

Examples:

# This is an example plugin that converts any sent image to sticker and replies it back.

import os
from pystark import Stark, filters
from pystark.helpers.stickers import to_webp


# filters.photo means that this function will be executed if any message has a photo.
@Stark.cmd(extra_filters=filters.photo)
async def reply_webp(_, msg):
    message = await msg.reply("Converting...")
    file = await msg.download()
    # main function
    sticker = await to_webp(file)
    await msg.reply_sticker(sticker)
    await message.delete()
    # remove your image and sticker later
    os.remove(sticker)
    os.remove(file)
Back to top