Last active
April 17, 2021 18:25
-
-
Save Wikinaut/5e13422f08cfaa6e35759aef65ecf2d1 to your computer and use it in GitHub Desktop.
Extend (or crop) the canvas background of an image to a multiple of a modulus (such as 32)
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 | |
if [ $# -lt 1 ]; then | |
echo "extend-crop-background <imagefile> [modulus [extent]]" | |
echo "Extend or crop image to a multiple of modulus ±'extent'" | |
echo | |
echo "modulus: default 32" | |
echo "extent: default=modulus" | |
echo | |
echo "Examples:" | |
echo "extend-crop-background in.jpg 32" | |
echo "extend-crop-background in.jpg 32 -32" | |
echo "extend-crop-background in.jpg 100 -32" | |
exit | |
fi | |
magick "$1" \ | |
-background none \ | |
-gravity center \ | |
-set option:xmod "${2:-32}" \ | |
-set option:zz "$3" \ | |
-set wx '%[fx:mod(w,xmod)==0?w:w-mod(w,xmod)+zz+xmod]' \ | |
-set hx '%[fx:mod(h,xmod)==0?h:h-mod(h,xmod)+zz+xmod]' \ | |
-extent '%[wx]x%[hx]' \ | |
-set filename:mod '%[xmod]' \ | |
-set filename:size '%wx%h' \ | |
-set filename:name '%t' \ | |
'%[filename:name]_mod%[filename:mod]-%[filename:size].png' | |
# to be used in a small script for composing small images as sprites in a bigger png | |
# | |
# #!/bin/bash | |
# | |
# if [ $# -lt 1 ] ; then | |
# echo "Make a sprite sheet from images" | |
# echo "Usage: make-sprite-sheet.sh *.png" | |
# exit | |
# fi | |
# | |
# now=$(date +"%Y%m%d-%H%M%S") | |
# for i in "$@";do extend-crop-background.sh "$i";done | |
# montage -mode concatenate -background transparent *.png sprite-sheet-${now}.png |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment