A powerful and efficient toolset for compressing and converting images to the WebP format, tailored for developers and web enthusiasts who aim to optimize their website's performance by reducing image sizes without compromising quality. 🚀
- Image Compression: 🗜️ Leverages the TinyPNG API to compress
.jpg
,.jpeg
, and.png
images effectively. - WebP Conversion: 🔄 Converts compressed images to the WebP format using the
Pillow
library, ensuring optimal file sizes for modern web usage. - Customizable Settings: ⚙️ Easily configure API keys, quality levels, and input/output directories through a centralized
config.py
file.
- Python 3.7+
Ensure Python is installed on your system.
To check your version:python --version
- TinyPNG API Key 🗝️
Sign up at TinyPNG Developers to obtain an API key.
git clone https://github.com/alireza-tahriri-masule/image-optimizer-toolset.git
cd image-optimizer-toolset
python -m venv venv
source venv/bin/activate # For Linux/Mac
venv\Scripts\activate # For Windows
Install all required libraries using the requirements.txt
file:
pip install -r requirements.txt
- Open the
config.py
file. - Add your TinyPNG API key to the
TINIFY_API_KEY
variable:TINIFY_API_KEY = "your-api-key-here"
- Update the quality level or directory paths if needed.
To compress all images in the input_images
directory and save them to the compressed_images
directory, run:
python compress_images.py
To convert the compressed images to WebP format and save them to the webp_images
directory, run:
python convert_to_webp.py
image-optimizer-toolset/
├── input_images/ # 📸 Directory for original images
├── compressed_images/ # 📦 Directory for compressed images
├── webp_images/ # 🌍 Directory for WebP images
├── compress_images.py # 🗜️ Script for compressing images
├── convert_to_webp.py # 🔄 Script for converting images to WebP
├── config.py # ⚙️ Configuration file for settings
├── requirements.txt # 📋 List of dependencies
└── README.md # 📚 Project documentation
The project relies on the following Python libraries:
tinify
🗜️: For interacting with the TinyPNG API.Pillow
🎨: For processing and converting images.
To install these dependencies:
pip install -r requirements.txt
- Place your images in the
input_images
folder. 📸 - Run
compress_images.py
to compress the images. 🗜️ - Run
convert_to_webp.py
to convert the compressed images to WebP format. 🔄 - Check the
compressed_images
andwebp_images
directories for the output. 📂
This project is open-source and available under the MIT License. 🎉
Feel free to fork the repository, make improvements, and submit pull requests. Any contributions are welcome! 💡