Skip to content

Instantly share code, notes, and snippets.

@leetrout
Forked from lafentres/all-the-way-downify.sh
Created April 20, 2023 17:41
Show Gist options
  • Save leetrout/1cc4a521da7b1e0a89f09b7759e936cb to your computer and use it in GitHub Desktop.
Save leetrout/1cc4a521da7b1e0a89f09b7759e936cb to your computer and use it in GitHub Desktop.
:*-all-the-way-down: Slack emoji creator, based off alisdair/intensify.sh
#!/bin/bash
# Credit to https://gist.github.com/alisdair/ffc7c884ee36ac132131f37e3803a1fe for the excellent original
# script that this one is based on. This script modifies the original to create the all-the-way-down effect.
# Generate a `:*-all-the-way-down:` Slack emoji, given a reasonable image
# input. I recommend grabbing an emoji from https://emojipedia.org/
set -euo pipefail
if [ $# -eq 0 ]; then
echo "Usage: $0 input.png"
exit 1
fi
file_path=$1
cd "$(dirname "$file_path")"
file=$(basename -- "$file_path")
file_name="${file%.*}"
# Scale to 128x128
scaled="${file%.*}-scaled.png"
convert \
-gravity center \
-background none \
-geometry 128x128 \
"${file}" \
"${scaled}"
# Generate tiled image for scrolling
tiled="${file%.*}-tiled.png"
convert \
-gravity center \
-background none \
-size 128x512 \
tile:"${scaled}" \
"${tiled}"
# Generate scrolling frames
frame="${file%.*}-frame"
n=0
count=16
pixels_to_scroll=8
while [ "$n" -lt "$count" ]; do
x=0
y=$((n * pixels_to_scroll))
# Scroll the image and crop it to 128x128
convert \
-gravity center \
-background none \
-roll "+${x}-${y}" \
-crop 128x128+0+0 \
+repage \
"${tiled}" \
"${frame}"-"${n}".gif
n=$((n + 1))
done
# Combine the frames into a GIF
combined="${file%.*}-combined.gif"
convert \
-background none \
-set dispose Background \
-delay 1x10 \
-loop 0 \
$(for i in $(seq 0 15); do echo ${frame}-${i}.gif; done) \
"${combined}"
# Trim the extra empty space off the GIF
gif="${file%.*}-all-the-way-down.gif"
convert \
"${combined}" \
-trim \
-layers trim-bounds \
"${gif}"
# Clean up
rm "${scaled}" "${tiled}" "${combined}" "${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