π« The Pain Point
Email attachment limit is 5MB. Your product photos are 8MB each. You need to compress them but not make them look terrible. Finding the right quality setting is trial and error.
π Agentic Solution
A Smart Compressor that automatically finds the optimal quality to hit your target file size.
Key Features:
- Target Size: Specify βunder 500KBβ and the script finds the right settings.
- Quality Floor: Never goes below a minimum quality threshold.
- Batch Processing: Process entire folders.
βοΈ Phase 1: Commander (Quick Fix)
For quick compression.
Prompt:
βI have a folder
photoswith large JPG images. Write a Python script using Pillow to:
- Target Size: Compress each image to under 500KB.
- Algorithm: Binary search for optimal quality (start at 85, adjust until under target).
- Minimum Quality: Never go below quality=30.
- Output: Save to
compressed/folder.Print progress with original and final file sizes. Skip files already under target size.β
Result: Email-ready images that still look good.
ποΈ Phase 2: Architect (Permanent Tool)
For Marketing Teams.
Engineering Prompt:
**Role:** Python Tool Developer
**Task:** Create a "Smart Image Compressor".
**Requirements:**
1. **GUI:**
* Select input folder.
* Target size input (KB or MB).
* Minimum quality slider.
* Resize option (max dimension).
* Progress bar with size savings.
2. **Logic:**
* Binary search for optimal quality.
* Option to resize before compressing.
* Show total space saved.
3. **Deliverables:**
* `smart_compress.py`
* `run.bat`, `run.sh`
* `requirements.txt`
π§ Prompt Decoding
- Binary Search: Instead of guessing quality, the script tests 50, then 75 or 25, narrowing down to the exact quality that hits the target size.
π οΈ Instructions
- Copy Prompt β Run.
- Set target size β Compress.