Last active
April 13, 2021 10:57
-
-
Save percysnoodle/adf6194ab0d991ba9bd3632f914d3e15 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# Generate a `:something-wow:` Slack emoji | |
# With thanks to https://gist.github.com/briancain/2efe69b8870be01bafde829d3933b2d3 | |
set -euo pipefail | |
if [ $# -eq 0 ]; then | |
echo "Usage: $0 input.png" | |
exit 1 | |
fi | |
input=$1 | |
cd "$(dirname "$input")" | |
fullsize=96 | |
filename=$(basename -- "$input") | |
basefile="${filename%.*}-base.png" | |
convert \ | |
-gravity center \ | |
-background none \ | |
-geometry "${fullsize}x${fullsize}" \ | |
"$filename" \ | |
"$basefile" | |
sizefile="${filename%.*}-size" | |
for i in 100 95 90 85 80 75; do | |
scaledsize=$((fullsize * 100 / i)) | |
scaledfile="${sizefile}-${i}.png" | |
convert \ | |
-gravity center \ | |
-background none \ | |
-extent "${scaledsize}x${scaledsize}" \ | |
-geometry "${fullsize}x${fullsize}" \ | |
"$basefile" \ | |
"$scaledfile" | |
done | |
frame="${filename%.*}-frame" | |
n=0 | |
for i in 100 95 90 85 80 75 80 85 90 95 100 95 90 85 80 75; do | |
cp "${sizefile}-${i}.png" "${frame}-$(printf %03d $n).gif" | |
n=$((n + 1)) | |
done | |
for angle in 45 90 135 180 225 270 315; do | |
convert \ | |
-gravity center \ | |
-distort ScaleRotateTranslate $angle \ | |
"${sizefile}-75.png" \ | |
"${frame}-$(printf %03d $n).gif" | |
n=$((n + 1)) | |
done | |
for i in 75 80 85 90 95; do | |
cp "${sizefile}-${i}.png" "${frame}-$(printf %03d $n).gif" | |
n=$((n + 1)) | |
done | |
# Combine the frames into a GIF | |
gif="${filename%.*}-wow.gif" | |
convert -background none -dispose Background -delay 1x100 -loop 0 "${frame}"-*.gif "$gif" | |
# Clean up | |
rm "${basefile}" "${sizefile}"-*.png "${frame}"-*.gif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment