Skip to content

Instantly share code, notes, and snippets.

@Wheest
Created April 18, 2020 12:07
Show Gist options
  • Save Wheest/84f9fca5ae78e3b0e4bc114845f18bb0 to your computer and use it in GitHub Desktop.
Save Wheest/84f9fca5ae78e3b0e4bc114845f18bb0 to your computer and use it in GitHub Desktop.
Rotate an animated gif by a chosen amount, while maintaining the animation
#!/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