Skip to content

Instantly share code, notes, and snippets.

@omers4
Forked from Kurobyte/gifAniChange.py
Last active December 2, 2024 00:21
Show Gist options
  • Select an option

  • Save omers4/9e7d90ee605e6545965c0f2f2a55f037 to your computer and use it in GitHub Desktop.

Select an option

Save omers4/9e7d90ee605e6545965c0f2f2a55f037 to your computer and use it in GitHub Desktop.
Python script that allows to change Gif animation loop count
import sys
import re
import binascii
pattern = b"\x4E\x45\x54\x53\x43\x41\x50\x45\x32\x2E\x30"
regex = re.compile(pattern)
rep = sys.argv[2]
with open(sys.argv[1], 'r+b') as f:
content = f.read()
for match_obj in regex.finditer(content):
offset = match_obj.start()
print("New repetitions value: " + rep)
f.seek(offset + 13)
nRep = hex(int(rep, 10))
f.write(binascii.unhexlify(nRep[2:].zfill(2)))
print('Done.')
input("Press Enter to continue...")
@omers4
Copy link
Author

omers4 commented Jan 27, 2024

Adjusted for Python 3

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