Split an image evenly with optional margins and colored background to create an IG-style grid layout
This file contains 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 | |
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