Skip to content
Nat Lee

Keyboard shortcuts

Turn these off if they get in the way of a screen reader or voice control. The setting is saved in this browser.

1
Home
2
Work
3
Projects
4
About
5
Experience
/
Search projects
?
Show this panel

Image Processing

Spin-off · Infortrend

Batch Crop Images

Batch Image Cropping Tool

Draw a crop box once and it is applied to a whole folder of similar images. Written because I refused to crop them one by one, and apparently other people refused too.

Role
Creator & Maintainer
Period
2019 – 2026.11
Status
Completed
Categories
Libraries & toolsVision & imaging
Origin
Infortrend
Stack
  • Python
  • OpenCV
  • NumPy
Batch Crop Images, screenshot 1

Overview

An efficient batch image processing tool that provides an intuitive interface for cropping multiple similar images simultaneously. This tool streamlines the workflow for processing large sets of images with consistent cropping requirements.

What it's good for

Screenshots, scans, video frames, product photos, dataset images: any folder that shares a layout gets the same crop in one pass. Names, formats, EXIF and colour profiles are kept, the originals are left alone, and a saved preset repeats the job later without a window.

Diagrams

Main paths only. The edge cases stayed in the code.

It used to start cropping the moment you let go of the mouse. Now it waits for Enter.

Point at a box to see what it connects to.

  1. List the pictures in the folder(Any letter case, name order) → Box already given?
  2. Box already given?(Via --box or a preset) → yes: Read the next picture's size → no: Open the reference picture
  3. Open the reference picture(First file by name) → Draw and adjust the box
  4. Draw and adjust the box(Arrow keys nudge 1 px) → Enter or Esc?
  5. Enter or Esc? → Enter: Print the box as --box → Esc: Quit, nothing written
  6. Quit, nothing written
  7. Print the box as --box(For reruns without the window) → Read the next picture's size
  8. Read the next picture's size(Headers only, nothing written yet) → Same size as the reference?
  9. Same size as the reference? → yes: More pictures to plan? → no: Which --mismatch rule?
  10. Which --mismatch rule? → ask, stretch: Stretch to the reference size → scale, anchor: Scale the box or anchor it → skip: Leave the picture out
  11. Stretch to the reference size(With ask, 'no' stops everything) → More pictures to plan?
  12. Scale the box or anchor it(Scale resizes it; anchor keeps size) → More pictures to plan?
  13. Leave the picture out → More pictures to plan?
  14. More pictures to plan? → yes: Read the next picture's size → no: Crop and write in parallel
  15. Crop and write in parallel(EXIF and ICC kept)

Features

  • Draw one crop box in an OpenCV window
  • Apply the same box across a folder
  • Headless --box input and saved presets

Results

  • Interactive or headless batch cropping with a pip-installable CLI
Draw a box, adjust it, lock 16:9, nudge it with the arrow keys, then crop the folder
Draw a box, adjust it, lock 16:9, nudge it with the arrow keys, then crop the folder

What I learned

  • Releasing the mouse used to start cropping at once; now Enter confirms, so the box can be adjusted first.
  • The size question used to come halfway through the batch. Planning now reads only image headers and asks first, so 'no' never leaves half a batch.
  • Upper-case extensions such as .JPG used to be skipped; now any letter case counts, and pictures go in name order.
  • The crop window: the box stays bright, the rest dims, the status bar shows exact pixels
    The crop window: the box stays bright, the rest dims, the status bar shows exact pixels
  • Spin-off · Infortrend
    Libraries & toolsVision & imaging7070 stars on GitHub

    Blur Generator

    Makes perfectly good images worse on purpose: motion, lens, Gaussian and depth-aware blur, for training models that have to cope with bad photos.

    2021Completed
  • Libraries & toolsVision & imaging2626 stars on GitHub

    HEIC2PNG

    Turns iPhone HEIC photos into PNG from the CLI, a shell pipe or Python. A small tool for a small, recurring annoyance.

    2022Completed
  • Spin-off · Infortrend
    Libraries & toolsVision & imaging1717 stars on GitHub

    Fisheye Warping

    Unrolls top-down fisheye images into panoramas and rolls them back again, so nobody has to squint at round photos.

    2020Completed