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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file telegram_sticker_utils-0.1.0.tar.gz.

File metadata

File hashes

Hashes for telegram_sticker_utils-0.1.0.tar.gz
Algorithm Hash digest
SHA256 04a182ca5dbd00ef22ad1f03323e67aa53962adc3bcd33ba90ccb0229fd4c66e
MD5 ff2cc9baf32844588533859861b002a3
BLAKE2b-256 38eb225058950b4741d4d9ae535f8e476b9a3223f6d609da50b14e1bb80ddd23

See more details on using hashes here.

Provenance

File details

Details for the file telegram_sticker_utils-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for telegram_sticker_utils-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4792f4b45761da5f1ee28cac94c389310c5759c54f65a910089c659cb707763f
MD5 3db9af9b14b8a878637f9ab5495792b0
BLAKE2b-256 51739975b4cd8a5faf76bad2e1897ad5fe6a3b3b273988efa164d119eb405e18

See more details on using hashes here.

Provenance

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