Skip to content

Instantly share code, notes, and snippets.

@luca-m
Created July 22, 2013 09:50
Show Gist options
  • Save luca-m/6052684 to your computer and use it in GitHub Desktop.
Save luca-m/6052684 to your computer and use it in GitHub Desktop.
Simple script for xorring toghether all layers of a GIF image. This work with indexed image, working with multi-channel images could need some modifications.
#!/usr/bin/env python
import Image
import sys
def xorImage( infile ):
try:
im = Image.open( infile )
except IOError:
print "Cant load", infile
sys.exit(1)
(w,h) = im.size
ss = [ [0]*w for x in range(h) ]
try:
while 1:
m = im.load()
for y in range(h):
for x in range(w):
ss[y][x] ^= m[x,y]
im.seek( im.tell() + 1 )
except EOFError:
im.seek(0)
m=im.load()
for y in range(h):
for x in range(w):
m[x,y]=ss[y][x]
im.save(infile+'-xor.bmp')
if __name__ == "__main__":
if len(sys.argv) < 2 :
print "GIF image xorrer. Xor all the layer of the image."
print "\tUsage %s <imagefile>" % sys.argv[0]
exit(-1)
xorImage(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment