Skip to content

Instantly share code, notes, and snippets.

@ifthenelse
Created April 19, 2026 15:44
Show Gist options
  • Select an option

  • Save ifthenelse/14b9a2c037a3d9628fae13ffe681d1da to your computer and use it in GitHub Desktop.

Select an option

Save ifthenelse/14b9a2c037a3d9628fae13ffe681d1da to your computer and use it in GitHub Desktop.
Zsh script to generate social share images from an image
#!/usr/bin/env zsh
# version
VERSION="1.0.0"
# --- functions ---
print_help() {
echo "Usage: $0 <input-image>"
echo ""
echo "Example:"
echo " $0 input.png"
echo ""
echo "Outputs:"
echo " gethired_share_rectangular.jpg (1200x630 ~1.91:1)"
echo " gethired_share_square.jpg (1200x1200 1:1)"
}
# --- flags ---
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
print_help
exit 0
fi
if [[ "$1" == "-v" || "$1" == "--version" ]]; then
echo "$VERSION"
exit 0
fi
# --- dependency check ---
if ! command -v magick >/dev/null 2>&1; then
echo "Error: ImageMagick (magick) not found."
echo "Install with:"
echo " brew install imagemagick"
exit 1
fi
# --- input check ---
INPUT="$1"
if [[ -z "$INPUT" || ! -f "$INPUT" ]]; then
echo "Error: input file missing or not found."
print_help
exit 1
fi
# --- Image 1: rectangular (contain, padded, ~1.91:1, final JPG) ---
magick "$INPUT" \
-resize 1200x630 \
-background none \
-gravity center \
-extent 1220x650 \
-resize 1200x630 \
-background white \
-alpha remove -alpha off \
gethired_share_rectangular.jpg
# --- Image 2: square (contain, padded, 1:1, final JPG) ---
magick "$INPUT" \
-resize 1200x1200 \
-background none \
-gravity center \
-extent 1220x1220 \
-resize 1200x1200 \
-background white \
-alpha remove -alpha off \
gethired_share_square.jpg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment