Skip to content

Instantly share code, notes, and snippets.

@firexcy
Last active July 8, 2024 10:32
Show Gist options
  • Save firexcy/98493f894ea80243a6b0c276a3477cc1 to your computer and use it in GitHub Desktop.
Save firexcy/98493f894ea80243a6b0c276a3477cc1 to your computer and use it in GitHub Desktop.
Split an image evenly with optional margins and colored background to create an IG-style grid layout
#!/bin/bash
file="$1"
background="white"
margin="0"
shift
while [ "$#" -gt 0 ]; do
case "$1" in
-background)
background="$2"
shift 2
;;
-margin)
margin="$2"
shift 2
;;
*)
echo "Error: Unknown option $1"
exit 1
;;
esac
done
extent="%[fx:max(w,h)*(1+$margin/100)]x%[fx:max(w,h)*(1+$margin/100)]"
echo "Margin set to $margin%"
echo "Backgound set to $background"
magick "$file"\
-gravity center\
-background "$background"\
-extent "$extent"\
+gravity\
-crop 3x3@\
grid-%d.jpg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment