easy and fast processing of telegram stickers
Project description
📦 Telegram Sticker Utils SDK
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file telegram_sticker_utils-0.1.0.tar.gz
.
File metadata
- Download URL: telegram_sticker_utils-0.1.0.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: pdm/2.12.4 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04a182ca5dbd00ef22ad1f03323e67aa53962adc3bcd33ba90ccb0229fd4c66e |
|
MD5 | ff2cc9baf32844588533859861b002a3 |
|
BLAKE2b-256 | 38eb225058950b4741d4d9ae535f8e476b9a3223f6d609da50b14e1bb80ddd23 |
Provenance
File details
Details for the file telegram_sticker_utils-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: telegram_sticker_utils-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: pdm/2.12.4 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4792f4b45761da5f1ee28cac94c389310c5759c54f65a910089c659cb707763f |
|
MD5 | 3db9af9b14b8a878637f9ab5495792b0 |
|
BLAKE2b-256 | 51739975b4cd8a5faf76bad2e1897ad5fe6a3b3b273988efa164d119eb405e18 |