简体中文 | English
AGPicCompress is a Python project for image compression, supporting JPEG and PNG formats.
-
For JPEG images, AGPicCompress uses mozjpeg for compression.
-
For PNG images, AGPicCompress uses pngquant for compression.
Both methods can reduce file size while maintaining visual quality, ensuring that the compressed images are visually indistinguishable or even losslessly compressed.
- Support batch processing
- Support exporting images in WebP format
AGPicCompress can be used completely offline. All image compression is done locally.
AGPicCompress uses a combination of algorithms and parameter configurations to minimize image file size while maintaining image quality as much as possible, meeting users' needs for image compression.
The above shows the comparison between the original and compressed JPEG and PNG images with default parameters. You can open or download the images to see the difference in quality and size.
You can follow the instructions below to install and configure AGPicCompress for image compression in your local environment.
AGPicCompress depends on mozjpeg and pngquant.
You may need to install pngquant manually. You can refer to the official pngquant documentation and add it to the appropriate location.
AGPicCompress will check for the existence of pngquant at the following locations, which you can configure freely:
- Environment variables (recommended)
- Under the AGPicCompress directory
- Under the
ext
directory in the AGPicCompress directory
This allows AGPicCompress to find pngquant and use it for PNG image compression.
You can obtain the code for the AGPicCompress project using the following methods:
git clone https://github.com/aoguai/AGPicCompress
cd AGPicCompress ## enter the AGPicCompress directory
pip install -r requirements.txt # install Python helpers' dependencies
You can run the AGPicCompress project using the following methods:
- Using the command line
You can also use the command
cd AGPicCompress ## enter the AGPicCompress directory python ImageCompressor.py <input_file> -o <output_file> -q <quality>
to view more help information.cd AGPicCompress ## enter the AGPicCompress directory python ImageCompressor.py --help
- Starting the Web Demo server
Then access the corresponding address, with the default address being
cd AGPicCompress ## enter the AGPicCompress directory python backend/main.py
http://localhost:8089/
- Using function calls
Please refer to the
from ImageCompressor import compress_image compress_image(input_file, output_file, quality)
compress_image
function inImageCompressor.py
for details.
AGPicCompress also provides executable files for the Windows environment. Windows users can directly download the executable files and follow the instructions to conveniently complete image compression tasks.
You can use AGPicCompress --help
to obtain relevant CLI parameter information and help:
Usage: AGPicCompress [OPTIONS] FP
Compress images via command line.
:param fp: Image file path or directory path. :type fp: Path
:param force: Whether to overwrite if a file with the same name exists,
defaults to False. :type force: bool
:param quality: Compression quality. 80-90, or 90, default is 80. :type
quality: int or tuple[int, int]
:param output: Output path or output directory. :type output: str
:param webp: Convert images to WebP format. :type webp: bool
Options:
-f, --force, --violent Whether to overwrite if a file with the same
name exists, defaults to False.
-q, --quality QUALITYINTEGER Compression quality. 80-90, or 90, default is
80.
-o, --output TEXT Output path or output directory.
--webp Convert images to WebP format.
--help Show this message and exit.
Thanks to the following open source projects for their support of AGPicCompress:
My related open source projects:
AGPicCompress was originally part of the project
AGPicCompress is an open-source project that appreciates all community involvement. To contribute to the project, follow the contribute guide.
AGPicCompress is open source under the GPL-3.0 license. Please refer to the LICENSE file for more details.