The script uses TinyPNG smart lossy compression techniques to reduce the file size of your JPG/PNG files. By selectively decreasing the number of colors in the image, fewer bytes are required to store the data. The effect is nearly invisible but it makes a very large difference in file size.
- Download and install the latest version of Python
- Clone this repo
git clone https://github.com/kerogenesis/image-optimizer.git
- Create and activate virtual environment
python3.9 -m venv venv
source venv/bin/activate
- Install dependencies
pip install -r requirements.txt
- Open
settings.py
in any text editor. - Add a key from tinypng.com/developers to the
API_KEY
field. - In the
USER_INPUT_PATH
field add a directory path with raw images. - In the
USER_OUTPUT_PATH
field add the directory path with compressed files.
You can also select the option to delete raw images after compression.
Create сompression.sh
file with:
#!/usr/bin/env bash
source path/to/venv/bin/activate && python3.9 path/to/image_optimizer.py
Give this file permission to execute:
chmod +x сompression.sh
Move it to any place (e.g. desktop) and run it.
Create compression.bat
file with:
@echo off
cmd /c "path\to\venv\Scripts\python.exe path\to\image_optimizer.py"
Move it to any place (e.g. desktop) and run it.
Remember the limit of 500 images per month on the free plan. You can change this at tinypng.com/dashboard/api