# 📦 Telegram Sticker Utils SDK
[![PyPI version](https://badge.fury.io/py/telegram-sticker-utils.svg)](https://badge.fury.io/py/telegram-sticker-utils)
[![Downloads](https://pepy.tech/badge/telegram-sticker-utils)](https://pepy.tech/project/telegram-sticker-utils)
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
- [x] Video Sticker
- [x] Static Sticker
- [ ] Animated Sticker
## 🚀 Installation
You need install [ffmpeg](https://ffmpeg.org/download.html) and [pngquant](https://pngquant.org/) before using this SDK.
```shell
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:
```python
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.
Raw data
{
"_id": null,
"home_page": null,
"name": "telegram-sticker-utils",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "telegram sticker image video processing ffmpeg pillow pngquant",
"author": null,
"author_email": "sudoskys <coldlando@hotmail.com>",
"download_url": "https://files.pythonhosted.org/packages/38/eb/225058950b4741d4d9ae535f8e476b9a3223f6d609da50b14e1bb80ddd23/telegram_sticker_utils-0.1.0.tar.gz",
"platform": null,
"description": "# \ud83d\udce6 Telegram Sticker Utils SDK\n\n[![PyPI version](https://badge.fury.io/py/telegram-sticker-utils.svg)](https://badge.fury.io/py/telegram-sticker-utils)\n[![Downloads](https://pepy.tech/badge/telegram-sticker-utils)](https://pepy.tech/project/telegram-sticker-utils)\n\nThis SDK provides a set of utilities for working with Telegram stickers.\n\n- Convert image formats without losing transparency.\n- Auto optimize output size for sticker, make it valid for Telegram.\n\n## \ud83d\udee0 Supported Pack Types\n\n- [x] Video Sticker\n- [x] Static Sticker\n- [ ] Animated Sticker\n\n## \ud83d\ude80 Installation\n\nYou need install [ffmpeg](https://ffmpeg.org/download.html) and [pngquant](https://pngquant.org/) before using this SDK.\n\n```shell\napt install ffmpeg\napt install pngquant\npip install telegram-sticker-utils\n```\n\n## \ud83d\udcdd Usage\n\nHere is a brief overview of the classes and methods provided by this SDK:\n\n```python\nfrom telegram_sticker_utils import TelegramStickerUtils\n\n# Create an instance of the class\nutils = TelegramStickerUtils()\nGIF_PATH = \"path_to_your_image.gif\"\nPNG_PATH = \"path_to_your_image.png\"\n\n# Check if an image is an animated GIF\nis_animated = utils.is_animated_gif('path_to_your_image.gif') # It will return True if the image is a TRUE GIF\nprint(is_animated)\n\nbytes_io, suffix = utils.make_video_sticker(GIF_PATH, scale=512, master_edge=\"width\") # or PNG_PATH\nprint(suffix)\nwith open(\"512.webm\", \"wb\") as f:\n f.write(bytes_io.getvalue())\n\nbytes_io, suffix2 = utils.make_static_sticker(PNG_PATH, scale=512, master_edge=\"width\") # or PNG_PATH\nprint(suffix2)\nwith open(\"512.png\", \"wb\") as f:\n f.write(bytes_io.getvalue())\n```\n\n### \ud83d\udcda TelegramStickerUtils API\n\nThis is the main class that provides all the functionality. It includes the following methods:\n\n- `is_animated_gif(image_path: str) -> bool`: Checks if an image is an animated GIF.\n- `resize_gif(input_path: str, output_path: str, new_width: int, new_height: int = -1) -> pathlib.Path`: Resizes a GIF\n file using ffmpeg.\n- `resize_png(input_path: str, output_path: str, new_width: int, new_height: int = -1) -> pathlib.Path`: Resizes an\n image file using ffmpeg.\n- `convert_gif_png(input_path: str, output_path: str, width: int, height: int) -> pathlib.Path`: Converts a GIF file to\n a PNG file.\n- `convert_gif_webm(input_path, sec: float = 2.9, bit_rate: str = '2000k', crf: int = 10, cpu_used: int = 2) -> BytesIO`:\n Converts a GIF file to a WebM file.\n- `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]`:\n Resizes a PNG file and optimizes it using pngquant.\n- `make_video_sticker(input_path: str, *, scale: int = 512, master_edge: Literal[\"width\", \"height\"] = \"width\", size_limit=256 * 1024) -> Tuple[BytesIO, str]`:\n Resizes a gif/png file and optimizes it using pngquant.\n\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "easy and fast processing of telegram stickers",
"version": "0.1.0",
"project_urls": {
"Repository": "https://github.com/sudoskys/telegram-sticker-utils"
},
"split_keywords": [
"telegram",
"sticker",
"image",
"video",
"processing",
"ffmpeg",
"pillow",
"pngquant"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "51739975b4cd8a5faf76bad2e1897ad5fe6a3b3b273988efa164d119eb405e18",
"md5": "3db9af9b14b8a878637f9ab5495792b0",
"sha256": "4792f4b45761da5f1ee28cac94c389310c5759c54f65a910089c659cb707763f"
},
"downloads": -1,
"filename": "telegram_sticker_utils-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3db9af9b14b8a878637f9ab5495792b0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 10128,
"upload_time": "2024-03-24T16:52:27",
"upload_time_iso_8601": "2024-03-24T16:52:27.007231Z",
"url": "https://files.pythonhosted.org/packages/51/73/9975b4cd8a5faf76bad2e1897ad5fe6a3b3b273988efa164d119eb405e18/telegram_sticker_utils-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "38eb225058950b4741d4d9ae535f8e476b9a3223f6d609da50b14e1bb80ddd23",
"md5": "ff2cc9baf32844588533859861b002a3",
"sha256": "04a182ca5dbd00ef22ad1f03323e67aa53962adc3bcd33ba90ccb0229fd4c66e"
},
"downloads": -1,
"filename": "telegram_sticker_utils-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "ff2cc9baf32844588533859861b002a3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 8836,
"upload_time": "2024-03-24T16:52:28",
"upload_time_iso_8601": "2024-03-24T16:52:28.572536Z",
"url": "https://files.pythonhosted.org/packages/38/eb/225058950b4741d4d9ae535f8e476b9a3223f6d609da50b14e1bb80ddd23/telegram_sticker_utils-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-24 16:52:28",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "sudoskys",
"github_project": "telegram-sticker-utils",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "telegram-sticker-utils"
}