Skip to content

Instantly share code, notes, and snippets.

@leingang
Last active January 28, 2026 19:30
Show Gist options
  • Select an option

  • Save leingang/d8066a0aa3d496f3e0aa65c1fb5f417a to your computer and use it in GitHub Desktop.

Select an option

Save leingang/d8066a0aa3d496f3e0aa65c1fb5f417a to your computer and use it in GitHub Desktop.
ImageMagick Batch Resize & Annotate
#!/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
@leingang
Copy link
Author

ImageMagick Batch Resize & Annotate

This script uses ImageMagick to:

  1. Resize multiple images to a fixed width (preserving aspect ratio)
  2. Overlay text in the lower-left corner of each image

It is written to work cleanly with ImageMagick 7 as installed by MacPorts,
which provides the convert command instead of the magick wrapper.


Requirements

  • ImageMagick 7
    • On macOS with MacPorts:
      sudo port install ImageMagick7

Verify installation:

convert -version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment