Skip to content

Instantly share code, notes, and snippets.

@alisdair
Created May 21, 2019 23:44
Show Gist options
  • Save alisdair/ffc7c884ee36ac132131f37e3803a1fe to your computer and use it in GitHub Desktop.
Save alisdair/ffc7c884ee36ac132131f37e3803a1fe to your computer and use it in GitHub Desktop.
intensifies Slack emoji creator
#!/bin/bash
# Generate a `:something-intensifies:` Slack emoji, given a reasonable image
# input. I recommend grabbing an emoji from https://emojipedia.org/
set -euo pipefail
# Number of frames of shaking
count=10
# Max pixels to move while shaking
delta=4
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"
# Generate some shaky frames
frame="${filename%.*}-frame"
n=0
while [ "$n" -lt "$count" ]; do
# Generate some random shake
x=$((RANDOM % (delta * 2) - delta))
y=$((RANDOM % (delta * 2) - delta))
# Ensure coordinates are of the form +3 or -4
[ "$x" -ge 0 ] && x="+$x"
[ "$y" -ge 0 ] && y="+$y"
# Shake the image!
convert "$extended" -page "${x}${y}" -background none -flatten "$frame"-"$n".gif
n=$((n + 1))
done
# Combine the frames into a GIF
gif="${filename%.*}-intensifies.gif"
convert -background none -dispose Background -delay 1x30 -loop 0 "${frame}"-*.gif "$gif"
# Clean up
rm "$extended" "${frame}"-*.gif
# We did it y'all
echo "Created $gif. Enjoy!"
@aicarmic
Copy link

aicarmic commented Jun 3, 2020

awesome script. note this relies on ImageMagick so you need to have that installed:
brew install ImageMagick

@cdanis
Copy link

cdanis commented Aug 5, 2020

nice! very similar to the approach I took for https://intensify.pictures/
(https://github.com/cdanis/intensify.pictures)

@fatcatt316
Copy link

Heck yeah, thanks for posting this!

@leosunmo
Copy link

leosunmo commented May 6, 2021

Works well! I did run in to issues with the final gif being too large. If you run in to the same issues, add this after the cleanup on line 60.

# Optimise if file is too big
if [[ $(stat --format=%s "$gif") -ge 128000 ]]; then
  convert "$gif" -fuzz 80% -layers Optimize "$gif"
fi

@martinb3
Copy link

martinb3 commented Sep 9, 2021

Made an infinite.sh version adapted from this! Thank you! :) https://gist.github.com/martinb3/289e5e210e9b2f8bc495854fed702c8d

@lafentres
Copy link

for reasons i still don't entirely understand, the script as it is now doesn't properly dispose of frames on my m1 max macbook pro (macos 12.4, imagemagick 7.1.0-29), resulting in this:

expand to see gif

eyes-intensifies1

however, if i modify line 57 by using set on the dispose setting like this:

convert -background none -set dispose Background -delay 1x30 -loop 0 "${frame}"-*.gif "$gif"

it works 🎉

expand to see gif

eyes-intensifies2

@TyJaYo
Copy link

TyJaYo commented Aug 31, 2023

I needed to make the adjustment above for my m1 mbp. Thanks, @lafentres!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment