Last active
January 28, 2026 19:30
-
-
Save leingang/d8066a0aa3d496f3e0aa65c1fb5f417a to your computer and use it in GitHub Desktop.
ImageMagick Batch Resize & Annotate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # | |
| # Batch resize images to a fixed width (preserving aspect ratio) | |
| # and overlay text in the lower-left corner. | |
| # | |
| # Requires: ImageMagick (MacPorts ImageMagick7 uses `convert`) | |
| # | |
| # ---- Configuration ---- | |
| WIDTH=800 | |
| TEXT="Sample Text" | |
| POINTSIZE=36 | |
| OFFSET="+20+20" | |
| UNDERCOLOR="#00000080" # semi-transparent black | |
| FILL="white" | |
| GRAVITY="southwest" | |
| # ---- Input check ---- | |
| if [ "$#" -eq 0 ]; then | |
| echo "Usage: $0 image1.jpg image2.jpg ..." | |
| exit 1 | |
| fi | |
| # ---- Processing ---- | |
| for img in "$@"; do | |
| out="out_$img" | |
| convert "$img" \ | |
| -resize "${WIDTH}x" \ | |
| -gravity "$GRAVITY" \ | |
| -pointsize "$POINTSIZE" \ | |
| -fill "$FILL" \ | |
| -undercolor "$UNDERCOLOR" \ | |
| -annotate "$OFFSET" "$TEXT" \ | |
| "$out" | |
| echo "Wrote $out" | |
| done |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ImageMagick Batch Resize & Annotate
This script uses ImageMagick to:
It is written to work cleanly with ImageMagick 7 as installed by MacPorts,
which provides the
convertcommand instead of themagickwrapper.Requirements
Verify installation: