Created
November 25, 2020 19:45
-
-
Save grocky/7c5638e1b910969d82ccf51c886164d6 to your computer and use it in GitHub Desktop.
Reduce a gif down to a desired number of frames
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
#!/usr/bin/env bash | |
# Reduce a gif down to a desired number of frames. | |
# Useful for really large gifs that you'd like to truncate. | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
PROJ_DIR=$(realpath "${DIR}/..") | |
TEMP_DIR=$(mktemp -d ) | |
REDUCED_DIR=$(mktemp -d) | |
function cleanup { | |
rm -rf "${TEMP_DIR}" | |
rm -rf "${REDUCED_DIR}" | |
} | |
trap cleanup EXIT | |
full_gif="${1}" | |
num_images=${2} | |
target_name="${3:-${full_gif%.*}-reduced.gif}" | |
convert "${PROJ_DIR}/${full_gif}" +adjoin ${TEMP_DIR}/temp_%03d.gif | |
for i in $(seq -w 0 ${num_images}); do | |
cp ${TEMP_DIR}/temp_${i}.gif ${REDUCED_DIR}/ | |
done | |
convert -delay 7 $(ls ${REDUCED_DIR}/*.gif) ${PROJ_DIR}/${target_name} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment