Skip to main content

easy and fast processing of telegram stickers

Project description

📦 Telegram Sticker Utils SDK

PyPI version Downloads

This SDK provides a set of utilities for working with Telegram stickers.

  • Convert image formats without losing transparency.
  • Auto optimize output size for sticker, make it valid for Telegram.

🛠 Supported Pack Types

  • Video Sticker
  • Static Sticker
  • Animated Sticker

🚀 Installation

You need install ffmpeg and pngquant before using this SDK.

apt install ffmpeg
apt install pngquant
pip install telegram-sticker-utils

📝 Usage

Here is a brief overview of the classes and methods provided by this SDK:

from telegram_sticker_utils import TelegramStickerUtils

# Create an instance of the class
utils = TelegramStickerUtils()
GIF_PATH = "path_to_your_image.gif"
PNG_PATH = "path_to_your_image.png"

# Check if an image is an animated GIF
is_animated = utils.is_animated_gif('path_to_your_image.gif')  # It will return True if the image is a TRUE GIF
print(is_animated)

bytes_io, suffix = utils.make_video_sticker(GIF_PATH, scale=512, master_edge="width")  # or PNG_PATH
print(suffix)
with open("512.webm", "wb") as f:
    f.write(bytes_io.getvalue())

bytes_io, suffix2 = utils.make_static_sticker(PNG_PATH, scale=512, master_edge="width")  # or PNG_PATH
print(suffix2)
with open("512.png", "wb") as f:
    f.write(bytes_io.getvalue())

📚 TelegramStickerUtils API

This is the main class that provides all the functionality. It includes the following methods:

  • is_animated_gif(image_path: str) -> bool: Checks if an image is an animated GIF.
  • resize_gif(input_path: str, output_path: str, new_width: int, new_height: int = -1) -> pathlib.Path: Resizes a GIF file using ffmpeg.
  • resize_png(input_path: str, output_path: str, new_width: int, new_height: int = -1) -> pathlib.Path: Resizes an image file using ffmpeg.
  • convert_gif_png(input_path: str, output_path: str, width: int, height: int) -> pathlib.Path: Converts a GIF file to a PNG file.
  • convert_gif_webm(input_path, sec: float = 2.9, bit_rate: str = '2000k', crf: int = 10, cpu_used: int = 2) -> BytesIO: Converts a GIF file to a WebM file.
  • make_static_sticker(input_path: str, *, scale: int = 512, master_edge: Literal["width", "height"] = "width", size_limit=500 * 1024, max_iterations=3) -> Tuple[BytesIO, str]: Resizes a PNG file and optimizes it using pngquant.
  • make_video_sticker(input_path: str, *, scale: int = 512, master_edge: Literal["width", "height"] = "width", size_limit=256 * 1024) -> Tuple[BytesIO, str]: Resizes a gif/png file and optimizes it using pngquant.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

telegram_sticker_utils-0.1.0.tar.gz (8.8 kB view hashes)

Uploaded Source

Built Distribution

telegram_sticker_utils-0.1.0-py3-none-any.whl (10.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page