https://github.com/angelhtml/image_compress
https://github.com/angelhtml/image_compress
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/angelhtml/image_compress
- Owner: angelhtml
- Created: 2025-04-01T14:18:47.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-01T14:27:30.000Z (over 1 year ago)
- Last Synced: 2025-04-01T15:38:13.016Z (over 1 year ago)
- Language: Python
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
How to Use This Script:
Install Pillow if you haven't: pip install pillow
Set the paths:
Replace "path/to/your/source/folder" with your source folder containing images
Replace "path/to/your/destination/folder" with where you want compressed images saved
Adjust settings (optional):
JPEG_QUALITY: 85 is good, lower for more compression
WEBP_QUALITY: 80 is good, lower for more compression
MAX_SIZE: Set maximum dimension (width/height) or None to keep original size
Run the script: python image_compressor.py
What It Does:
Reads all supported image files from the source folder
For each image:
Converts to RGB if needed (for JPEG compatibility)
Resizes if MAX_SIZE is specified
Creates three compressed versions:
JPEG with quality optimization
PNG with optimization
WebP (usually the best compression)
Saves all compressed versions to the destination folder
Preserves original filenames but adds suffixes (_compressed.jpg, _optimized.png, etc.)
Handles errors gracefully and reports progress
Supported Image Formats:
The script handles JPG, JPEG, PNG, WebP, BMP, and GIF files. You can modify the SUPPORTED_EXTENSIONS tuple if needed.