Created
April 18, 2020 12:07
-
-
Save Wheest/84f9fca5ae78e3b0e4bc114845f18bb0 to your computer and use it in GitHub Desktop.
Rotate an animated gif by a chosen amount, while maintaining the animation
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 | |
# Rotate an animated gif by a chosen amount, while maintaining the animation | |
if [ "$1" == "-h" ]; then | |
echo "Usage: `basename $0` [rotation in degrees] [input file] [output file]" | |
exit 0 | |
fi | |
ROTATION=$1 | |
INPUT=$2 | |
OUTPUT=$3 | |
TMP_DIR=$(mktemp -d) | |
# Arg checks | |
if ! [[ "$ROTATION" =~ ^[0-9]+$ ]] | |
then | |
echo "Sorry integers only for rotation" | |
fi | |
# Split original gif | |
convert $INPUT -scene 1 +adjoin "$TMP_DIR/tmp_%02d.gif" | |
# Rotate frames | |
mogrify -rotate $ROTATION -alpha set -background none "$TMP_DIR/tmp_*.gif" | |
# Combine frames | |
convert "$TMP_DIR/tmp_*.gif" -loop 0 $OUTPUT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment