Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/bin/bash
set -ux
WORKDIR=`mktemp -d "tmp-image.XXXXXX"`
input=$1
output=$2
convert ${input} -background white -alpha deactivate -flatten -resize 128x128 ${WORKDIR}/input.png
# top left
for i in `seq 0 15`; do
index=`expr $i + 0`
move=`expr 128 - $i \* 8`
convert ${WORKDIR}/input.png -virtual-pixel White -distort Affine "0,0 0,${move}" ${WORKDIR}/img-top-left-$(printf %02d $index).png
done
for i in `seq 0 15`; do
index=`expr $i + 16`
move=`expr $i \* 8`
convert ${WORKDIR}/input.png -virtual-pixel White -distort Affine "0,0 ${move},0" ${WORKDIR}/img-top-left-$(printf %02d $index).png
done
# top right
for i in `seq 0 15`; do
index=`expr $i + 0`
move=`expr 128 - $i \* 8`
convert ${WORKDIR}/input.png -virtual-pixel White -distort Affine "${move},0 0,0" ${WORKDIR}/img-top-right-$(printf %02d $index).png
done
for i in `seq 0 15`; do
index=`expr $i + 16`
move=`expr $i \* 8`
convert ${WORKDIR}/input.png -virtual-pixel White -distort Affine "0,0 0,${move}" ${WORKDIR}/img-top-right-$(printf %02d $index).png
done
# bottom left
for i in `seq 0 15`; do
index=`expr $i + 0`
move=`expr 128 - $i \* 8`
convert ${WORKDIR}/input.png -virtual-pixel White -distort Affine "0,0 ${move},0" ${WORKDIR}/img-bottom-left-$(printf %02d $index).png
done
for i in `seq 0 15`; do
index=`expr $i + 16`
move=`expr $i \* 8`
convert ${WORKDIR}/input.png -virtual-pixel White -distort Affine "0,${move} 0,0" ${WORKDIR}/img-bottom-left-$(printf %02d $index).png
done
# bottom right
for i in `seq 0 15`; do
index=`expr $i + 0`
move=`expr 128 - $i \* 8`
convert ${WORKDIR}/input.png -virtual-pixel White -distort Affine "0,${move} 0,0" ${WORKDIR}/img-bottom-right-$(printf %02d $index).png
done
for i in `seq 0 15`; do
index=`expr $i + 16`
move=`expr $i \* 8`
convert ${WORKDIR}/input.png -virtual-pixel White -distort Affine "${move},0 0,0" ${WORKDIR}/img-bottom-right-$(printf %02d $index).png
done
# middle left
for i in `seq 0 15`; do
index=`expr $i + 0`
move=`expr $i \* 8`
convert ${WORKDIR}/input.png -virtual-pixel White -distort Affine "0,${move} 0,0" ${WORKDIR}/img-middle-left-$(printf %02d $index).png
done
for i in `seq 0 15`; do
index=`expr $i + 16`
move=`expr 128 - $i \* 8`
convert ${WORKDIR}/input.png -virtual-pixel White -distort Affine "0,0 0,${move}" ${WORKDIR}/img-middle-left-$(printf %02d $index).png
done
# middle right
for i in `seq 0 15`; do
index=`expr $i + 0`
move=`expr $i \* 8`
convert ${WORKDIR}/input.png -virtual-pixel White -distort Affine "0,0 0,${move}" ${WORKDIR}/img-middle-right-$(printf %02d $index).png
done
for i in `seq 0 15`; do
index=`expr $i + 16`
move=`expr 128 - $i \* 8`
convert ${WORKDIR}/input.png -virtual-pixel White -distort Affine "0,${move} 0,0" ${WORKDIR}/img-middle-right-$(printf %02d $index).png
done
# top center
for i in `seq 0 15`; do
index=`expr $i + 0`
move=`expr $i \* 8`
convert ${WORKDIR}/input.png -virtual-pixel White -distort Affine "0,0 ${move},0" ${WORKDIR}/img-top-center-$(printf %02d $index).png
done
for i in `seq 0 15`; do
index=`expr $i + 16`
move=`expr 128 - $i \* 8`
convert ${WORKDIR}/input.png -virtual-pixel White -distort Affine "${move},0 0,0" ${WORKDIR}/img-top-center-$(printf %02d $index).png
done
# bottom center
for i in `seq 0 15`; do
index=`expr $i + 0`
move=`expr $i \* 8`
convert ${WORKDIR}/input.png -virtual-pixel White -distort Affine "${move},0 0,0" ${WORKDIR}/img-bottom-center-$(printf %02d $index).png
done
for i in `seq 0 15`; do
index=`expr $i + 16`
move=`expr 128 - $i \* 8`
convert ${WORKDIR}/input.png -virtual-pixel White -distort Affine "0,0 ${move},0" ${WORKDIR}/img-bottom-center-$(printf %02d $index).png
done
convert -layers Optimize -loop 0 -delay 4 -colors 80 -fuzz 11% ${WORKDIR}/img-top-left-*.png top-left-${output}
convert -layers Optimize -loop 0 -delay 4 -colors 80 -fuzz 11% ${WORKDIR}/img-top-right-*.png top-right-${output}
convert -layers Optimize -loop 0 -delay 4 -colors 80 -fuzz 11% ${WORKDIR}/img-bottom-left-*.png bottom-left-${output}
convert -layers Optimize -loop 0 -delay 4 -colors 80 -fuzz 11% ${WORKDIR}/img-bottom-right-*.png bottom-right-${output}
convert -layers Optimize -loop 0 -delay 4 -colors 80 -fuzz 11% ${WORKDIR}/img-middle-left-*.png middle-left-${output}
convert -layers Optimize -loop 0 -delay 4 -colors 80 -fuzz 11% ${WORKDIR}/img-middle-right-*.png middle-right-${output}
convert -layers Optimize -loop 0 -delay 4 -colors 80 -fuzz 11% ${WORKDIR}/img-top-center-*.png top-center-${output}
convert -layers Optimize -loop 0 -delay 4 -colors 80 -fuzz 11% ${WORKDIR}/img-bottom-center-*.png bottom-center-${output}
rm -rf ${WORKDIR}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment