🖼️

Auto Crop to Square

Automatically crop images to perfect squares using smart center detection or padding.

Image ⭐ Beginner ⏱️ 3 minutes

😫 The Pain Point

E-commerce platforms require square product images. Your catalog has mixed aspect ratios - some landscape, some portrait. Manually cropping each image to center the product takes forever.

🚀 Agentic Solution

A Smart Cropper that detects the best center point and crops or adds padding automatically.

Key Features:

  • Smart Center: Detects product position and centers the crop.
  • Padding Option: Adds white/transparent padding instead of cropping.
  • Batch Processing: Handles entire folders with progress tracking.

⚔️ Phase 1: Commander (Quick Fix)

For quick cropping.

Prompt:

“I have a folder products with varied aspect ratio images. Write a Python script using Pillow to:

  1. Crop Mode: Center-crop each image to a perfect square (use shorter dimension).
  2. Alternative Padding Mode: Or add white padding to make square (preserving full image).
  3. Output: Save to squared/ folder as JPG (quality=90).
  4. Error Handling: Skip corrupt files with warning.

Print progress log. Accept --mode crop or --mode pad argument.”

Result: Perfectly square images ready for upload.

🏗️ Phase 2: Architect (Permanent Tool)

For Content Teams.

Engineering Prompt:

**Role:** Python GUI Developer (PyQt6 Specialist)
**Task:** Create "Smart Square Cropper" Desktop App

**Objective:** A desktop application to batch crop or pad product images to perfect squares.

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

**Functional Requirements:**
1.  **UI Layout (PyQt6):**
    *   **Input:** Source Folder selection.
    *   **Controls:** Radio buttons for "Center Crop" vs "Add Padding" (White/Transparent).
    *   **Size:** Input field for Target Size (default 1000px).
    *   **Preview:** Before/After toggle view.
    *   *Constraint:* Clean, modern native UI.

2.  **Core Logic:**
    *   **Crop Mode:** Calculate center offset and crop shortest dimension.
    *   **Pad Mode:** Create specific size canvas and paste image in center.
    *   **Threading:** Process whole folder in background thread with Progress Bar.

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

  • Center Crop vs Padding: Two different use cases. Crop loses data but looks cleaner. Padding preserves everything but may look less polished.

🛠️ Instructions

  1. Copy Prompt → Paste → Run.
  2. Choose mode → Process folder.

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.