A Telegram bot that validates image URLs, downloads the pictures, compresses them, and shares the compressed picture back with the user.
- Validates user-submitted URLs to ensure they are valid and accessible.
- Checks if the URL returns a 200 HTTP status code (no 404 or invalid URLs).
- Retrieves file metadata, such as image size, without downloading the image.
- Downloads the image in the background.
- Compresses the image with efficient settings.
- Sends the compressed image back to the user as a downloadable file.
-
Clone the repository:
git clone https://github.com/basemax/telegram-image-compressor.git cd telegram-image-compressor
-
Install the required Python packages:
pip install -r requirements.txt
-
Set up your bot token:
Obtain a bot token from BotFather on Telegram.
Replace YOUR_BOT_TOKEN
in the main.py
script with your actual bot token.
Start the bot:
python main.py
Send a image URL to the bot in Telegram.
The bot will:
- Validate the URL.
- Download the image.
- Compress the image using Python.
- Send the compressed image back to you.
User sends:
https://example.com/image.jpg
Bot responds:
✅ URL is valid!
🔄 Downloading image...
🗜️ Compressing image...
📤 Sending compressed image...
- Python 3.7+
- requests Python library
- python-telegram-bot library
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please fork this repository and submit a pull request with your changes.
Feel free to reach out for any questions or suggestions: @basemax
Copyright 2024, Max Base