Created
June 11, 2025 19:40
-
-
Save tsuharesu/dfe751e3a79a65b0ff7509cea07d821f to your computer and use it in GitHub Desktop.
Image edit with 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/bash | |
INPUT_DIR="input" | |
OUTPUT_DIR="output" | |
RESIZE_DIMENSIONS="1080x1080" | |
BLUR_RADIUS="0x50" # Standard deviation (0 for auto-radius) x Sigma (how much blur) | |
# Adjust Sigma (e.g., 5, 10, 15) for more or less blur | |
BORDER_SIZE="8" # Border thickness in pixels for the original image | |
BORDER_COLOR="white" # Color of the border | |
WATERMARK_IMAGE="watermark.png" | |
WATERMARK_SIZE="100x100" | |
WATERMARK_OFFSET="+0+0" # Horizontal + Vertical offset from gravity (e.g., +20+20 for 20px from right/bottom) | |
mkdir -p "$OUTPUT_DIR" | |
for photo in "$INPUT_DIR"/*.jpg; do | |
if [ -f "$photo" ]; then | |
filename=$(basename "$photo") | |
output_path="$OUTPUT_DIR/$filename" | |
echo "Processing $filename..." | |
# Creates a blur of the original image and expand it to fill a 1080x1080 canvas | |
magick "$photo" \ | |
-write mpr:original \ | |
-blur "$BLUR_RADIUS" \ | |
-resize "${RESIZE_DIMENSIONS}^" \ | |
-gravity center \ | |
-extent "$RESIZE_DIMENSIONS" \ | |
# Copy the original photo and fit it on this canvas, applying a border | |
\( mpr:original \ | |
-shave "${BORDER_SIZE}x${BORDER_SIZE}" \ | |
-bordercolor "$BORDER_COLOR" \ | |
-border "${BORDER_SIZE}" \ | |
-resize "${RESIZE_DIMENSIONS}>" \) \ | |
-gravity center \ | |
-composite \ | |
# Apply a watermark image on the bottom-right corner of the image | |
\( "$WATERMARK_IMAGE" -resize "${WATERMARK_SIZE}>" \ | |
-channel A -evaluate multiply 0.5 +channel \) \ | |
-gravity southeast \ | |
-geometry "$WATERMARK_OFFSET" \ | |
-composite \ | |
"$output_path" | |
fi | |
done | |
echo "All photos processed." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment