Last active
October 16, 2021 05:28
-
-
Save walfie/8ab39f150e23a303c2cd3d24644a7de3 to your computer and use it in GitHub Desktop.
My process of turning a Callipeg export of PNG frames into gifs and spritesheets
This file contains hidden or 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
export NAME="my-animation" | |
export WIDTH=815 | |
export HEIGHT=950 | |
export BG_COLOR="#d1ccff" | |
export SPRITESHEET_SIZE=5x3 | |
export TINIFY_API_KEY="..." | |
# Assuming frames have been exported to `~/Downloads/`... | |
# Make directories | |
mkdir ~/Pictures/animations/$NAME/{original,cropped} | |
# Move PNG frames from `~/Downloads` to the newest directory in `~/Pictures/animations` | |
find ~/Downloads -maxdepth 1 -regex '.*[0-9].png' -exec mv {} ~/Pictures/animations/$(/bin/ls -t ~/Pictures/animations/ | head -n 1)/original/ \; | |
cd ~/Pictures/animations/$NAME/original | |
# Add a leading 0 in front of single-digit frames | |
rename 's/_(\d\.)/_0$1/g' -- *.png | |
# Crop the original images | |
mogrify +repage -crop $WIDTH"x"$HEIGHT+0+0 +repage -path ../cropped *_*.png | |
# Generate gif | |
cd ../cropped | |
convert -limit thread 1 -delay 4.16666666666 -alpha set -dispose previous +dither *_*.png out-transparent.gif && convert -limit thread 1 -delay 4.16666666666 *_*.png -background "$BG_COLOR" -alpha remove -alpha off +dither out.gif | |
# Make spritesheet | |
montage -border 0 -tile $SPRITESHEET_SIZE -geometry $WIDTH"x" -background none *_*.png spritesheet-unoptimized.png | |
# Optimize spritesheet | |
curl $(curl --user api:$TINIFY_API_KEY --data-binary @spritesheet-unoptimized.png https://api.tinify.com/shrink | jq -r .output.url) >spritesheet.png | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment