-
-
Save martinb3/289e5e210e9b2f8bc495854fed702c8d 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 | |
# All credit goes to https://gist.github.com/alisdair/ffc7c884ee36ac132131f37e3803a1fe for the original script. | |
# This is only a slight modification to allow for a scrolling version of the transform. | |
# Generate a `:infinite-something:` Slack emoji, given a reasonable image | |
# input. I recommend grabbing an emoji from https://emojipedia.org/ | |
set -euo pipefail | |
# Number of frames of scrolling | |
count=10 | |
# Max pixels to move while scrolling | |
delta=12 | |
if [ $# -eq 0 ]; then | |
echo "Usage: $0 input.png" | |
exit 1 | |
fi | |
input=$1 | |
cd "$(dirname "$input")" | |
filename=$(basename -- "$input") | |
# Add 10% padding to width and height, then scale to 128x128 | |
width=$(identify -format "%w" "$filename") | |
height=$(identify -format "%h" "$filename") | |
new_width=$(( width + width / 10 )) | |
new_height=$(( height + height / 10 )) | |
extended="${filename%.*}-extended.png" | |
convert \ | |
-gravity center \ | |
-background none \ | |
-extent ${new_width}x${new_height} \ | |
-geometry 128x128 \ | |
"$filename" \ | |
"$extended" | |
montage="${filename%.*}-montage.png" | |
montage \ | |
"${extended}" \ | |
"${extended}" \ | |
"${extended}" \ | |
"${extended}" \ | |
"${extended}" \ | |
"${extended}" \ | |
"${extended}" \ | |
"${extended}" \ | |
"${extended}" \ | |
"${extended}" \ | |
"${extended}" \ | |
"${extended}" \ | |
"${extended}" \ | |
"${extended}" \ | |
"${extended}" \ | |
"${extended}" \ | |
-geometry -8-8+0 -adjoin \ | |
"${montage}" | |
# Generate some shaky frames | |
frame="${filename%.*}-frame" | |
n=0 | |
while [ "$n" -lt "$count" ]; do | |
# Scroll the image | |
x=$((n * delta)) | |
y=$((n * delta)) | |
# Ensure coordinates are of the form +3 or -4 | |
[ "$x" -ge 0 ] && x="+$x" | |
[ "$y" -ge 0 ] && y="+$y" | |
# Shake the image! | |
convert "$montage" -roll "$x$y" -background none -flatten "$frame"-"$n".gif | |
n=$((n + 1)) | |
done | |
# Combine the frames into a GIF | |
gif="infinite-${filename%.*}.gif" | |
convert -background none -dispose Background -delay 1x30 -loop 0 "${frame}"-*.gif "$gif" | |
# Clean up | |
rm "$extended" "${montage}" "${frame}"-*.gif | |
# We did it y'all | |
echo "Created $gif. Enjoy!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment