Skip to content

Instantly share code, notes, and snippets.

@MichaelChirico
Last active September 22, 2020 03:44
Show Gist options
  • Save MichaelChirico/6735712523be771b5ec2ac74815c933a to your computer and use it in GitHub Desktop.
Save MichaelChirico/6735712523be771b5ec2ac74815c933a to your computer and use it in GitHub Desktop.
flop (horizontal flip) + mirror a gif
#/bin/sh
# built on ImageMagick tools via convert; constituent SO answers:
# https://askubuntu.com/a/101527/362864
# https://askubuntu.com/a/1052902/362864
# https://stackoverflow.com/a/20075227/3576984
# https://unix.stackexchange.com/a/24019/112834
# INPUT: foo.gif
# step 0: isolate foo to its own folder
TMPDIR=/tmp/__flop_mirror__
mkdir -p $TMPDIR
cp foo.gif $TMPDIR/ && cd $TMPDIR
# step 1: gif -> frames [%03d if the gif has > 100 frames, etc]
convert foo.gif foo-frame-%02d.png
# step 2: flop frames
# * -flip to do vertical flip
for FRAME in foo-frame*.png; do convert -flop $FRAME flop-$FRAME; done
# step 3: concat horizontally framewise
# * - swap file order to swap output order
# * -append to concatenate vertically
for FRAME in foo-frame*.png; do convert $FRAME flop-$FRAME +append combined-$FRAME; done
# step 4: combine as gif
# * check speed of output and tinker with -delay
# (not sure if it's possible to read this from the input file?)
convert -delay 10 -loop 0 combined-foo-frame*.png combined-foo.gif
# step 5: clean up
cp combined-foo.gif /desired/path/combined-foo.gif
cd /desired/path
rm -rf $TMPDIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment