Command-line application for lossy compression of JPEG images, ideal for improving load time of websites.
Each image's final quality is iteratively determined using the structural similarity (SSIM) algorithm, so
that the visual difference between original and compressed picture is optimal. Detailed results
are saved to log.txt
.
The SSIM algorithm is implemented in Cython to increase performance.
Supported input image types are: JPEG
- Use pip to install requirements:
pip install -r requirements.txt
- Navigate to app directory and compile the Cython module:
python setup.py build_ext --inplace
- Run:
python compressor.py [input dir] [output dir] [maximum dimension] [SSIM factor]
input dir
: Path to directory with original imagesoutput dir
: Path to directory where compressed images will be storedmaximum dimension
: Optional; Maximum dimension in pixels to further reduce file size. If used, the aspect ratio will be preserved and width/height (whichever larger) will be set to this number.SSIM factor
: Optional; [0-1.0] SSIM factor, default value of 0.97 usually gives optimal results for most images
After compiling the Cython module you can run unit tests with:
pytest
- Python 3.9
- Cython