---
name: crop-image
description: Crop, trim, and adjust framing of images by removing transparent whitespace margins, trimming solid color borders, or extracting specific pixel bounding boxes. Use when the user asks to crop an image, trim blank space or transparent borders, remove excess margins, or inspect subject dimensions.
compatibility: Python 3.9+ (zero dependencies for PNG; optional Pillow for JPEG/WebP)
title: crop-image
canonical_url: https://skilld.dev/gh/domesticmouse/skills/crop-image
last_updated: 2026-11-12T12:20:49.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [scripts/crop.py](https://skilld.dev/api/skills-raw/domesticmouse/skills/crop-image/scripts/crop.py).
>
> If the user asked to install this Skill, run `npx skilld install domesticmouse/skills/crop-image`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/crop-image`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/domesticmouse/skills/crop-image) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/crop-image`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/crop-image --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/crop-image --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Crop Image

Procedural runbook and tooling for inspecting image boundaries, trimming empty margins (transparent or solid color backgrounds), and executing precision crops.

Includes a zero-dependency Python 3 utility ([crop.py](https://skilld.dev/api/skills-raw/domesticmouse/skills/crop-image/scripts/crop.py)) for bit-perfect PNG handling and automatic fallback to Pillow when installed.

## Workflows

Choose the matching workflow based on your objective:

1. [Inspect Image & Subject Bounding Box](#1-inspect-image--subject-bounding-box)
2. [Autocrop Transparent Blank Space](#2-autocrop-transparent-blank-space)
3. [Trim Solid Color Borders (White / Black / Custom)](#3-trim-solid-color-borders-white--black--custom)
4. [Crop by Explicit Bounding Box or Dimensions](#4-crop-by-explicit-bounding-box-or-dimensions)
5. [Validate Cropped Asset](#5-validate-cropped-asset)

---

### 1. Inspect Image & Subject Bounding Box

Before modifying an image, inspect its current dimensions, color channels, and where the actual subject pixels reside.

1. Run the inspection command using [crop.py](https://skilld.dev/api/skills-raw/domesticmouse/skills/crop-image/scripts/crop.py):
   ```bash
   python3 .agents/skills/crop-image/scripts/crop.py <path/to/image> --inspect
   ```
2. Review the diagnostic output:
   - **Dimensions**: Overall pixel width and height.
   - **Detected Border/Corner Color**: Color sampled from corners.
   - **Alpha Subject Bounding Box**: Coordinate extent `[left, top, right, bottom]` where alpha > 0.
   - **Subject Margins**: Number of blank pixels on left, right, top, and bottom edges. (Note: iOS Simulator captures taken via `xcrun simctl io booted screenshot /abs/path/to/file.png`—see `/ios-simulator-screenshot`—capture the exact device framebuffer with `0px` outer margin, whereas macOS window captures include transparent shadow margins that need `--autocrop`.)
3. *Completion Criterion*: Bounding box coordinates and margin sizes are printed to stdout without modifying the source image.

---

### 2. Autocrop Transparent Blank Space

Remove excess transparent padding around a subject, optionally preserving a small aesthetic margin (e.g. 8–16 px) so the graphic does not touch container boundaries.

1. Run autocrop with desired padding (default is 0 for tight crop):
   ```bash
   # In-place overwrite with 12px padding around subject:
   python3 .agents/skills/crop-image/scripts/crop.py <path/to/image.png> --autocrop --padding 12 --in-place
   
   # Or output to a new file:
   python3 .agents/skills/crop-image/scripts/crop.py <input.png> -o <output.png> --autocrop --padding 12
   ```
2. For semi-transparent edge artifacts, increase `--alpha-thresh` (e.g. `--alpha-thresh 10`).
3. *Completion Criterion*: Target image exists on disk with reduced dimensions tightly bounding the subject.

---

### 3. Trim Solid Color Borders (White / Black / Custom)

Trim uniform solid background colors (e.g. white borders `255,255,255` or dark borders `0,0,0`):

1. Specify the RGB color to trim and tolerance (0–255):
   ```bash
   # Trim pure white border with tolerance 5 and 10px margin:
   python3 .agents/skills/crop-image/scripts/crop.py <path/to/image> -o <output> --autocrop --color 255,255,255 --tolerance 5 --padding 10
   
   # Trim pure black border:
   python3 .agents/skills/crop-image/scripts/crop.py <path/to/image> -o <output> --autocrop --color 0,0,0 --tolerance 5
   ```
2. *Completion Criterion*: Script reports `Success` with adjusted dimensions matching the bounded subject.

---

### 4. Crop by Explicit Bounding Box or Dimensions

Extract a specific rectangle by pixel coordinates `left,top,right,bottom` (inclusive):

1. Compute or select the target coordinates `left,top,right,bottom`:
   ```bash
   python3 .agents/skills/crop-image/scripts/crop.py <path/to/image> -o <output> --box 100,50,900,650
   ```
2. If working on macOS and only cropping from the center or fixed width/height:
   ```bash
   sips --cropToHeightWidth <targetHeight> <targetWidth> <input> --out <output>
   ```
3. *Completion Criterion*: Output image matches the exact target pixel dimensions `(right - left + 1) × (bottom - top + 1)`.

---

### 5. Validate Cropped Asset

Always verify the cropped image before declaring completion:

1. Query file metadata with `sips` (macOS) or [crop.py](https://skilld.dev/api/skills-raw/domesticmouse/skills/crop-image/scripts/crop.py) `--inspect`:
   ```bash
   sips -g pixelWidth -g pixelHeight <path/to/cropped-image>
   python3 .agents/skills/crop-image/scripts/crop.py <path/to/cropped-image> --inspect
   ```
2. Confirm:
   - `pixelWidth` and `pixelHeight` match expected cropped dimensions.
   - The file is readable and not corrupted.
   - For web/slides projects, run local build/linter (e.g. `npm --prefix slides run build`) to ensure layouts using the asset compile cleanly.
3. *Completion Criterion*: Image metadata returns expected dimensions and project build exits with code 0.
