Last active
May 24, 2022 05:44
-
-
Save boaheck/3ed71924d7fdc5eb3d32a8444dc2194b to your computer and use it in GitHub Desktop.
ImageGlitcher
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
#!/usr/bin/env python | |
import random | |
import sys | |
cutLength = 1 | |
pasteDist = 1 | |
frames = 20 | |
imgSequence = False | |
''' | |
So what we do is split the file into 4 parts: | |
0. The head is 8 bytes long and should not ever be fucked This doesn't apply to jpgs and has the potential to cause problems. | |
1. part1 is the bit between head and cutpos. | |
2. part2 is the next cutLenght number of bits to be cut out. | |
3. part3 is the rest. | |
then we put it together like this: | |
head + | |
part1 + | |
the first pasteDist bits of part3 + | |
part 2 + | |
the rest of part3 | |
then we write this back to the file and the bits smoosh about the rgba channels. | |
''' | |
def fuckItUp(fileName,saveFileName): | |
imgFile = open(fileName,'r+b') | |
imgBuff = imgFile.read() | |
head = imgBuff[0:64] | |
cutPos = random.randrange(64,(len(imgBuff))-(cutLength+pasteDist)) | |
pastePos = cutPos+cutLength | |
part1 = imgBuff[64:cutPos] | |
part2 = imgBuff[pastePos:] | |
part3 = imgBuff[cutPos:pastePos] | |
imgFile.close() | |
savFile = open(saveFileName,'w+b') | |
savFile.write(head + part1 + imgBuff[pastePos:pastePos+pasteDist] + part3 + imgBuff[pastePos+pasteDist:]) | |
savFile.close() | |
if __name__ == '__main__': | |
if len(sys.argv) > 1: | |
if(frames > 1): | |
fileToFuck = sys.argv[1] | |
for i in range(0,frames): | |
if imgSequence: | |
saveLoc = 'frames\\' + sys.argv[1][0:-4] + '-' + str(i) + sys.argv[1][-4:] | |
else: | |
saveLoc = 'glitched'+sys.argv[1] | |
fuckItUp(fileToFuck,saveLoc) | |
fileToFuck = saveLoc | |
else: | |
fuckItUp(sys.argv[1],'glitched'+sys.argv[1]) | |
else: | |
print('please provide a filename as an argument') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment