Console/terminal utility that batch-resizes images to a padded square (letterbox), supporting Windows 11 and Ubuntu Linux 24.04. Every image is scaled so its longer side equals the value given by --size, with the aspect ratio preserved, then padded with black borders to a square and written to the target folder under the same name.

 

Jupyter-Image-Batch-Resize.png

 

[Folder Structure]

  • CLAUDE.md / AGENT.md: program specification (identical content).
  • CHANGELOG.md: change log.
  • copyright.txt: copyright notice.
  • data/from/: source examples, 1.jpg to 10.jpg.
  • data/to/: the 320x320 letterboxed results, written by the script.
  • tool/tools.py: shared helpers.
  • src/: source code, launcher scripts and this document.
  • venv/: Python virtual environment, created by step 01.

[Instructions]

1. 01_venv_create.bat / 01_venv_create.sh

Delete the old venv/, create a fresh one and install src/requirements.txt. Aborts loudly if pip fails.

 

2. 02_venv_activate.bat / 02_venv_activate.sh

Activate the virtual environment. On Linux use source src/02_venv_activate.sh.

 

3. 03_batch_resize.bat / 03_batch_resize.sh

Letterbox every image from the --from folder into the --to folder at the size given by --size.

 

4. 99_venv_clear.bat / 99_venv_clear.sh

Delete the venv/ folder.

 

[Python Entry Point]

src/batch_resize.py

  • --from data/from: source folder
  • --to data/to: target folder
  • --size 320: the side length of the square output

Scaling uses cv2.INTER_AREA, and the black padding is added with cv2.copyMakeBorder and split evenly between both sides (portrait images are padded left and right, landscape images top and bottom). The target folder is created when missing, and unreadable files are skipped.

 

[Quick Start]

Windows 11

src\01_venv_create.bat

src\03_batch_resize.bat

 

Ubuntu Linux 24.04

bash src/01_venv_create.sh

bash src/03_batch_resize.sh

 

For your own files, for example: src\03_batch_resize.bat --from path\to\images --to path\to\output --size 640

 

[References]

This SDK is built in AppForAI - AI Dev Tools.

 

Purchase license separately: USD 600, permanent authorization, single APP authorization, single machine authorization, one-year activation, one-year download, one-year update, one-year email technical support.