Created
January 22, 2019 07:36
-
-
Save unex/7c4f4a07389c091d27fa25439aff94ab to your computer and use it in GitHub Desktop.
Glitches GIFs for https://steamcommunity.com/sharedfiles/filedetails/?id=1627692828
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
""" | |
Steam Long Workshop / Guide GIF Glitcher | |
======================================== | |
https://github.com/notderw/ | |
======================================== | |
THIS SCRIPT IS EXPERIMENTAL! | |
If you have any issues, please leave a comment detailing any errors you are having. | |
If this script does not work on your GIF, try using the HEX editor method detailed | |
in the guide below. | |
Original Guide: https://steamcommunity.com/sharedfiles/filedetails/?id=1627692828 | |
This script replaces the hex editor step in the above guide. | |
Requirements: Python 3.6+ (?) (Tested on 3.7.0) | |
TLDR steps: | |
1. Split your gif into 160px wide sections | |
2. Add 100px of extra space to the bottom of each | |
3. Run this script on each, Ex: 'python gif_glitcher.py <source image>' | |
4. Upload to Steam (see guide for specific instructions) | |
""" | |
import os, sys | |
import struct | |
import re | |
if len(sys.argv) < 2: | |
print(f'Usage: {sys.argv[0]} <source image>') | |
sys.exit(1) | |
infile = sys.argv[1] | |
outfile = os.path.splitext(infile)[0] + "_glitched.gif" | |
with open(infile, "rb") as infile: | |
b = infile.read() | |
# Get the 4 resolution bytes | |
res = b[6:10] | |
# Get the actual resolution pixels | |
h, w = divmod(struct.unpack("<I", res)[0], 256) | |
h //= 256 | |
print(f'Image size: {w}x{h} ({w}x{h - 100} after resize)') | |
print(f'Found {len(re.findall(b[6:10], b))} resolution instances') | |
# Create glitched resolution bytes | |
new_res = struct.pack('<I', ((h - 100) * 256) * 256 + w) | |
# Replace normal resolution bytes with glitched ones | |
glitched = re.sub(b[6:10], new_res, b) | |
with open(outfile, 'wb') as of: | |
of.write(glitched) | |
print(f'Wrote file {outfile}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment