Image Compression Tool

The cover image was generated by ChatGPT.
Introduction
When creating website pages, we sometimes notice that some pages take a while to load, while others do not. After comparing different webpages, the conclusion is that if the images on the webpage are too large, it causes slower page loading speeds. Therefore, the idea arose to find a tool that can compress all the images under the current website directory.
However, after searching extensively online, no suitable application was found. In the end, the decision was made to create a program that can compress all images.
Requirements
Before starting development, I confirmed the following requirements:
- Ability to adjust the compression level of images.
- Option to keep the original images in their original directory for easy reuse later.
- Ability to skip unnecessary images or those that have already been compressed.
- Ability to generate a compression report to confirm the amount of space saved.
The tool introduced here is built based on the above requirements encountered so far. This article does not delve into how to develop this tool but only introduces how to use it. If you have any suggestions or corrections for this tool, you are welcome to leave a comment.
Project Image Compression Tool
Image Compression Tool is a command-line image compression utility developed in Python. It supports compressing all images in a specified folder, automatically backs up the original images, skips images that were already compressed, and generates detailed compression reports (CSV files).
This project is developed in Python, mainly using the PIL module for image compression. Supported image formats include: .jpg, .jpeg, .png, .webp, .bmp, .tiff, .gif, .avif, .heic.
Among these, .png format compression is less efficient. In some cases, if the image cannot be compressed further or if the compression quality is set too low, the compressed file may end up larger than the original.
- Language: Traditional Chinese / English
- Version: v.1.0 / v.1140621
- Last updated: June 21, 2025
Development Environment
Operating system environment as follows:
| Item | Description |
|---|---|
| Operating System | Windows 11 24H2 |
| Python | Version 3.12.9 |
Modules used:
| Module | pip package name | Version |
|---|---|---|
PIL | pillow | 11.0.0 |
tqdm | tqdm | 4.67.1 |
yaml | PyYAML | 6.0.2 |
Please install the above modules before use. You can use requirements.txt to install all at once:
| |
Parameter Description
| Parameter | Option | Description | Default |
|---|---|---|---|
--path | Required | Specify the folder path to compress | None |
--compress_quality | Optional | Compression quality, range 1-100. Lower value means higher compression but possibly more damage | 85 |
--backup | Optional | Whether to backup original images (True or False) | True |
--backup_folder | Optional | Folder name to store backup original images | original image |
--original_suffix | Optional | Suffix added to backup original image filenames | _original |
--skip_suffix | Optional | Images with filenames containing this suffix will be skipped | _skip |
--skip_original | Optional | Whether to skip already backed up images (filenames containing original_suffix) | True |
--skip_skip | Optional | Whether to skip images marked to skip (filenames containing skip_suffix) | True |
--print_image_reduced | Optional | Whether to print compression results of each image | True |
--print_summary | Optional | Whether to print compression summary report | True |
--save_summary_to_csv | Optional | Whether to save the compression summary as a CSV file | True |
--summary_folder | Optional | Folder to save the compression summary report | summary |
--summary_filename | Optional | Filename for the compression summary report (without extension) | report |
--config | Optional | Path to YAML configuration file | config.yaml |
--lang_code | Optional | Language code, e.g., zh-tw, en | zh-tw |
--version | Optional | Display program version info and exit | None |
--about | Optional | Display author, version, license, Email, GitHub info | None |
--author | Optional | Display author information | None |
--license | Optional | Display license information | None |
--status | Optional | Display current status (defined by the program) | None |
--github | Optional | Display GitHub page link | None |
--help | Optional | Show help documentation | None |
How to Use
- Direct compression with default settings (specify folder)
| |
- Use
config.yamlconfiguration file and suppress per-image compression output
| |
- Display author information
| |
- Display help documentation
| |
Configuration
Modify default values
If you want to modify the default values in the config file or create a new config file, please copy or edit the /config.yaml file in the project root directory.
config.yaml
| |
Add a New Language File
To modify the default values of the language file or add a new language file, please copy or edit the /language/language.yaml file located in the project root directory.
en.yaml
| |
License
MIT License
Copyright © 2025 Josh-test-lab
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Conclusion
This project was entirely a spontaneous idea. As an amateur programming enthusiast without any formal training, being able to write a fully functional tool from scratch is an exciting accomplishment for me. Although this tool is far from perfect and still requires rewriting and improvement in many areas, it genuinely solved a real problem I encountered in practice. This kind of “made-for-myself” mindset has given it special value.
At school, most of our training focuses on using rigorous logic for mathematical reasoning and statistical analysis. Through this hands-on experience, I realized that such logical thinking can be extended and applied to a wide range of fields. I believe I didn’t just write a script, I took the first step toward real-world practice. Translating what I’ve learned into something tangible through a keyboard has given me a sense of achievement. I hope this passion will continue, allowing me to explore the unknown, bridge disciplines, and create more fun and useful tools.
If you have any suggestions about this project, or if there are parts of the code that need to be corrected or rewritten, feel free to leave a comment.
See Also
- The GitHub repository of this project.
![[Test] Website Network Connection Speed Test](https://josh-test-lab.github.io/posts/Website%20Network%20Connection%20Speed%20Test/cover%20image.webp)




