Created
April 14, 2026 17:27
-
-
Save charlesbedrosian/584fcda77be007ad328e11c9e7de6bda to your computer and use it in GitHub Desktop.
Generate placeholder image with text overlay
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 | |
| set -euo pipefail | |
| if [ $# -eq 0 ]; then | |
| echo "Usage: $0 \"Your text here\"" | |
| exit 1 | |
| fi | |
| TEXT="$*" | |
| FILENAME=$(echo "$TEXT" | sed 's/\\n/_/g; s/[^A-Za-z0-9]/_/g; s/__*/_/g').jpg | |
| # Convert literal \n to actual newlines | |
| TEXT="${TEXT//\\n/$'\n'}" | |
| TMPIMG=$(mktemp /tmp/loremflickr_XXXXXX.jpg) | |
| trap 'rm -f "$TMPIMG"' EXIT | |
| # Download a random nature image from Lorem Flickr (1300x900) | |
| echo "Downloading image..." | |
| curl -sL -o "$TMPIMG" "https://loremflickr.com/1300/900/nature" | |
| # Determine average brightness of the image (0-255 scale) | |
| BRIGHTNESS=$(magick "$TMPIMG" -colorspace Gray -resize 1x1! -format "%[fx:int(mean*255)]" info:) | |
| echo "Image average brightness: $BRIGHTNESS" | |
| # Choose text and stroke colors that contrast with the image | |
| if [ "$BRIGHTNESS" -gt 128 ]; then | |
| TEXT_COLOR="black" | |
| STROKE_COLOR="white" | |
| else | |
| TEXT_COLOR="white" | |
| STROKE_COLOR="black" | |
| fi | |
| echo "Using $TEXT_COLOR text with $STROKE_COLOR outline" | |
| # Overlay text centered on the image with Arial Black, wrapping long lines | |
| magick "$TMPIMG" \ | |
| \( -background none \ | |
| -font "/System/Library/Fonts/Supplemental/Arial Black.ttf" \ | |
| -fill "$TEXT_COLOR" \ | |
| -stroke "$STROKE_COLOR" \ | |
| -strokewidth 2 \ | |
| -size 1260x860 \ | |
| -gravity center \ | |
| caption:"$TEXT" \) \ | |
| -gravity center \ | |
| -composite \ | |
| "$FILENAME" | |
| echo "Saved: $FILENAME" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment