This Python script compresses images in a specified folder and saves the compressed versions in an output folder. It supports .jpg, .jpeg, and .png files. PNG images are converted to JPEG to save more space.
- Compress
.jpg,.jpeg, and.pngimages. - Convert PNG images to JPEG for better compression.
- Preserve original filenames in the output folder.
- Customizable image quality (default is 90%).
- Automatically creates the output folder if it doesn’t exist.
- Displays progress in the console with image numbers and paths.
- Handles exceptions gracefully for invalid or corrupted files.
- Python 3.x
- Pillow library
Install Pillow using pip if not already installed: pip install Pillow
- Clone or download the script.
- Set the input and output folder paths:
input_folder_path = "D:/file path"
output_folder_path = "C:/final path"- Call the function with optional
qualityparameter (default is 90):
compress_images(input_folder=input_folder_path, output_folder=output_folder_path, quality=90)- Run the script:
python compress_images.pyThe compressed images will appear in the specified output folder.