🖼️

Smart Compress

Intelligently compress images to a target file size while maintaining visual quality.

Image ⭐ Beginner ⏱️ 3 minutes

😫 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 photos with large JPG images. Write a Python script using Pillow to:

  1. Target Size: Compress each image to under 500KB.
  2. Algorithm: Binary search for optimal quality (start at 85, adjust until under target).
  3. Minimum Quality: Never go below quality=30.
  4. 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 GUI Developer (PyQt6 Specialist)
**Task:** Create "Smart Image Compressor" Desktop App

**Objective:** A batch tool to compress images to a specific target file size (e.g., <500KB) automatically.

**Tech Stack:**
* Language: Python 3.10+
* GUI Library: PyQt6 (Cross-platform)
* Image Processing: Pillow
* Packaging: PyInstaller

**Functional Requirements:**
1.  **UI Layout (PyQt6):**
    *   **Input:** Folder selection.
    *   **Goal:** Target Size Input (KB/MB).
    *   **Constraints:** "Minimum Quality" Slider limit.
    *   **Results:** Table showing "Original Size" vs "Optimized Size" and "Space Saved".

2.  **Core Logic:**
    *   **Binary Search:** Iteratively save to a memory buffer to find the highest quality that fits the target size.
    *   **Threading:** Multithreaded compression loop.

3.  **Deliverables:**
    *   `main.py`: Complete source code.
    *   `requirements.txt`: Dependencies.
    *   **Build Instructions:**
        *   Windows: `pyinstaller --onefile --noconsole main.py`
        *   macOS: `pyinstaller --windowed --noconsole main.py`

🧠 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

  1. Copy Prompt → Run.
  2. Set target size → Compress.

Related Workflows

Explore other categories

📬

Get Started with Agentic Working

Subscribe to receive updates from AgenticWorking.io

📖 Free eBook Guide 📦 7 Ready-to-use Scripts 🔔 Weekly Tips

No spam, unsubscribe anytime. Join 1,000+ subscribers.