Created
November 28, 2013 12:52
-
-
Save sfan5/7691401 to your computer and use it in GitHub Desktop.
Makes each PNG only show the difference to the previous ones pasted on top of eachother
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 sys | |
from PIL import Image | |
def rgb_rgba_cmp(a, b): | |
if a[0] != b[0]: | |
return False | |
if a[1] != b[1]: | |
return False | |
if a[2] != b[2]: | |
return False | |
return True | |
if len(sys.argv) <= 1: | |
print("Usage: %s <inputs>" % sys.argv[0]) | |
else: | |
base = Image.open(sys.argv[1]) | |
basep = base.load() | |
i = 0 | |
for cif in sys.argv[2:]: | |
ci = Image.open(cif) | |
if ci.mode != "RGBA": | |
ci = ci.convert("RGBA") | |
cip = ci.load() | |
for x in range(base.size[0]): | |
for y in range(base.size[1]): | |
if rgb_rgba_cmp(basep[x, y], cip[x, y]): | |
cip[x, y] = (0, 0, 0, 0) | |
ci.save(cif) | |
base.paste(ci, (0, 0), ci) | |
i += 1 | |
sys.stdout.write("%05d/%05d\r" % (i, len(sys.argv)-2)) | |
sys.stdout.flush() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment