Skip to content

Instantly share code, notes, and snippets.

@Kurobyte
Created September 29, 2015 21:05
Show Gist options
  • Select an option

  • Save Kurobyte/956239fbd35d6d53c8a2 to your computer and use it in GitHub Desktop.

Select an option

Save Kurobyte/956239fbd35d6d53c8a2 to your computer and use it in GitHub Desktop.
Python script that allows to change Gif animation loop count
# Change GIF nº animation loop count
# Usage: python script.py "path-to-image" <number>
#
# Number: 0 to infinite loop. Enter other number to set that loop count
import sys, re;
import binascii;
pattern = "\x4E\x45\x54\x53\x43\x41\x50\x45\x32\x2E\x30";
regex = re.compile(pattern);
rep = sys.argv[2];
f = open(sys.argv[1], 'r+b');
for match_obj in regex.finditer(f.read()):
offset = match_obj.start();
print "New repetitions value: "+rep;
f.seek(offset + 13);
nRep = hex(int(rep, 10));
f.write(nRep);
print 'Done.';
raw_input("Press Enter to continue...");
@TerminalPR0
Copy link

THANK YOU

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