- Install Python 3+
- Install git
- Clone this repository:
git clone https://github.com/georgekhananaev/py-image-compressor.git
- Install requirements.txt, cd into main folder and
type:
pip install -r requirements.txt
Command | Weight | Default Values | Meaning | Details | Usage example |
---|---|---|---|---|---|
-l | required | N/A | location | your images path, where your original images located. | -l "C:/Original Images/" |
-d | optional | /data/output/ | destination | your destination path, compressed images will be saved here | -d "C:/Compressed Images/" |
-w | optional | 1920 | max width | if larger resolution will be set to max width without breaking the image ratio | -w 1920 |
-q | optional | 80 | quality | images quality by percentage. lower quality to save more space |
-q 80 |
-f | optional | jpeg | format | supported format ".png", ".jpeg", ".jpg", ".ppm", ".gif", ".tiff", ".bmp", ".webp", ".heic", ".heif" for more check PIL Documentation. |
-f jpeg |
-r | optional | no | remove | remove images from destination path, if compression is worst than original file. |
-r y |
-h | - | - | help | if you forgot what command you want to use can write python main.py --help | -h or --help |
Import: for -l and -d, use quotation marks if have spaces.
Examples:
python main.py -l <Your Location> -d <Your Destination> -f <File Format> -w <Max Width> -q <Max Quality> -r <Remove Larger Files>
COMMAND:
python main.py -l "D:/Programming/React/resume-website/" -d "./data/out/" -f webp -w 500 -q 100
02/12/2023 👇
- Add a condition in the imageCompressor for automatic RGB and RGBA detection and selection. Thanks to "ZenithVal" for the suggestion.
06/04/2023 👇
- Updated readme.md.
- Updated requirements.txt with latest versions packages.
12/12/2022 👇️
- Added a 'resources' folder containing a configurations.ini file to store all program settings. This change sets the stage for an upcoming GUI interface with memory.
- Removed PySimpleGUI from dependencies; instead, we will use customtkinter for a modern-looking GUI.
06/12/2022 👇️
- Default values have been added for the -d, -f, and -q options, making them no longer required fields. You can execute the code simply by typing: python main.py -l "C:/Your Folder/". The default values are as follows: JPEG format, 80% quality, maximum width of 1080p, and the destination folder is set to /data/output/_
- Simplified the code using *args and **kwargs.
05/12/2022 👇️
- Added support for .heif and .heic formats, so now you can convert photos from your iPhone as well.
- Updated requirements.txt to include PySimpleGUI (for future implementations) and pillow-heif.
04/12/2022 👇️
- Improved the image processing output to display the actual amount of size saved for each image. >
- Better output for each image, you can see how much size you actually saved.
- I have started developing the GUI interface, which will be executable on both Windows and Ubuntu.
- I've added a new command -r y to prevent retaining larger compressed images.
- Due to my busy schedule, I will continue development only if there is substantial demand.
- If you encounter any bugs, please feel free to open an issue.
- Personally, I use this script to compress images for React-based websites and convert entire folders to WebP format with a single command.