Skip to content

Instantly share code, notes, and snippets.

@genevera
Created February 9, 2024 20:24
Show Gist options
  • Save genevera/3ad8293540a91d855d4706853b120ef8 to your computer and use it in GitHub Desktop.
Save genevera/3ad8293540a91d855d4706853b120ef8 to your computer and use it in GitHub Desktop.
giflooop - creates a forward-reverse loop of any animated gif
################################################################################
# creates a fwd-reverse loop of any gif
################################################################################
function gifloop {
local -r original="${1:-UNSET}";
local -r original_254="/tmp/${original/.gif/_254.gif}";
local -r loop_unopt="/tmp/${original/.gif/_loop_unopt.gif}";
local -r output="${original/.gif/_loop.gif}";
if [[ "${orignal}" == "UNSET" ]]; then
echo "Please pass in a gif filename.";
exit 1;
fi;
"$(command -v gifsicle)" --colors=255 "${original}" -o "${original_254}";
"$(command -v gifsicle)" --unoptimize "${original_254}" "${original_254}" "#-1-0" -o "${loop_unopt}";
"$(command -v gifsicle)" --unoptimize "${loop_unopt}" "${loop_unopt}" "#-1-0" -O3 --lossy -o "${output}";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment