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.pngimages effectively. - WebP Conversion: 🔄 Converts compressed images to the WebP format using the
Pillowlibrary, ensuring optimal file sizes for modern web usage. - Customizable Settings: ⚙️ Easily configure API keys, quality levels, and input/output directories through a centralized
config.pyfile.
- 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-toolsetpython -m venv venv
source venv/bin/activate # For Linux/Mac
venv\Scripts\activate # For WindowsInstall all required libraries using the requirements.txt file:
pip install -r requirements.txt- Open the
config.pyfile. - Add your TinyPNG API key to the
TINIFY_API_KEYvariable: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.pyTo convert the compressed images to WebP format and save them to the webp_images directory, run:
python convert_to_webp.pyimage-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_imagesfolder. 📸 - Run
compress_images.pyto compress the images. 🗜️ - Run
convert_to_webp.pyto convert the compressed images to WebP format. 🔄 - Check the
compressed_imagesandwebp_imagesdirectories 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! 💡