Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
remove every second frame of GIF with gifsicle
#!/bin/bash
# This script will take an animated GIF and delete every other frame
# Accepts two parameters: input file and output file
# Usage: ./<scriptfilename> input.gif output.gif
# Make a copy of the file
cp $1 $2
echo "copy completed"
# Get the number of frames
numframes=`gifsicle $1 -I | grep -P "\d+ images" --only-matching | grep -P "\d+" --only-matching`
echo "numframes completed"
# Deletion
gifsicle "$1" --unoptimize $(seq -f "#%g" 0 2 $numframes) -O2 -o "$2"
echo "script completed"
@ulf1

This comment has been minimized.

Copy link

commented Jun 23, 2016

thank you. i found it useful

@rjsteinert

This comment has been minimized.

Copy link

commented Jul 26, 2017

Failed on macOS for me. Ended up with a Gif with probably about three frames at the beginning.

screen shot 2017-07-26 at 5 02 23 pm

@h3xx

This comment has been minimized.

Copy link

commented Jul 28, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.