Created
March 18, 2026 05:57
-
-
Save truongduyng/0c80dcab995dbc2a6255e506f9247899 to your computer and use it in GitHub Desktop.
macOS Quick Action that adds a random gradient background + drop shadow to images. Supports batch processing — just select multiple files in Finder, right-click, and go. Requires ImageMagick.
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
| #!/bin/zsh | |
| # Add Random Gradient Background + Drop Shadow - macOS Quick Action Script | |
| # Requires: ImageMagick (brew install imagemagick) | |
| export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH" | |
| for INPUT_FILE in "$@"; do | |
| FILENAME=$(basename "$INPUT_FILE") | |
| DIRNAME=$(dirname "$INPUT_FILE") | |
| EXTENSION="${FILENAME##*.}" | |
| BASENAME="${FILENAME%.*}" | |
| OUTPUT_FILE="${DIRNAME}/${BASENAME}_gradient.${EXTENSION}" | |
| # Get image dimensions | |
| WIDTH=$(magick identify -format "%w" "$INPUT_FILE") | |
| HEIGHT=$(magick identify -format "%h" "$INPUT_FILE") | |
| # Generate random colors (hex), avoid near-white (brightness < 200) | |
| MAX_BRIGHTNESS=200 | |
| while true; do | |
| R1=$((RANDOM % 256)); G1=$((RANDOM % 256)); B1=$((RANDOM % 256)) | |
| BRIGHTNESS1=$(( (R1 + G1 + B1) / 3 )) | |
| [[ $BRIGHTNESS1 -lt $MAX_BRIGHTNESS ]] && break | |
| done | |
| while true; do | |
| R2=$((RANDOM % 256)); G2=$((RANDOM % 256)); B2=$((RANDOM % 256)) | |
| BRIGHTNESS2=$(( (R2 + G2 + B2) / 3 )) | |
| [[ $BRIGHTNESS2 -lt $MAX_BRIGHTNESS ]] && break | |
| done | |
| COLOR1=$(printf '#%02X%02X%02X' $R1 $G1 $B1) | |
| COLOR2=$(printf '#%02X%02X%02X' $R2 $G2 $B2) | |
| # Random gradient direction | |
| DIRECTIONS=("0" "45" "90" "135" "180" "225" "270" "315") | |
| ANGLE=${DIRECTIONS[$((RANDOM % ${#DIRECTIONS[@]}))]} | |
| # Settings | |
| PADDING=80 # space around image | |
| SHADOW_OFFSET=12 # shadow offset in px | |
| SHADOW_BLUR=18 # shadow softness | |
| SHADOW_OPACITY=70 # shadow darkness (0-100) | |
| CANVAS_W=$((WIDTH + PADDING * 2)) | |
| CANVAS_H=$((HEIGHT + PADDING * 2)) | |
| # Create gradient → add shadow to image → composite on gradient | |
| magick \ | |
| -size "${CANVAS_W}x${CANVAS_H}" \ | |
| "gradient:${COLOR1}-${COLOR2}" \ | |
| -define gradient:angle="${ANGLE}" \ | |
| \( "$INPUT_FILE" \ | |
| \( +clone \ | |
| -background "rgba(0,0,0,${SHADOW_OPACITY})" \ | |
| -shadow "${SHADOW_OPACITY}x${SHADOW_BLUR}+${SHADOW_OFFSET}+${SHADOW_OFFSET}" \ | |
| \) \ | |
| +swap \ | |
| -background none \ | |
| -layers merge \ | |
| \) \ | |
| -gravity center \ | |
| -composite \ | |
| "$OUTPUT_FILE" | |
| echo "✅ Saved: $OUTPUT_FILE" | |
| echo " Gradient: $COLOR1 → $COLOR2 | Angle: ${ANGLE}° | Shadow: offset=${SHADOW_OFFSET}px blur=${SHADOW_BLUR}px" | |
| done |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A macOS Quick Action script that adds a random gradient background + drop shadow to any image (or batch of images) directly from Finder's right-click menu. Powered by ImageMagick.
What it does
yourfile_gradient.jpg) — original is untouchedRequirements
Step 1 — Install ImageMagick
Open Terminal and run:
Verify it's working:
Step 2 — Create the Quick Action in Automator
⌘ Space→ typeAutomator)image filesFinder/bin/zshas argumentsStep 3 — Save the Quick Action
⌘ Sto saveAdd Gradient BackgroundStep 4 — Use it in Finder
yourimage_gradient.jpgwill appear in the same folderCustomization
You can tweak these four variables inside the script:
PADDING80SHADOW_OFFSET12SHADOW_BLUR18SHADOW_OPACITY70MAX_BRIGHTNESS200Troubleshooting
Quick Action doesn't appear in Finder
killall Findermagick: command not foundbrew install imagemagick/bin/zshTest it in Terminal first
This shows the exact error if something goes wrong.
Output example