1
0
Fork 0
cc-stuff/badapple-tape.py

29 lines
924 B
Python
Raw Normal View History

2023-10-15 04:26:23 +03:00
#!/usr/bin/env python3
# x-run: python3 % badapple.bin ~/videos/badapple/frame*.png
from sys import argv
from PIL import Image
w, h = 82, 40
bits = [[1,2],[4,8],[16,0]]
with open(argv[1], "wb") as fp:
fp.write(bytes([w, h]))
for i, f in enumerate(argv[2:]):
with Image.open(f) as im:
img = im.resize((w * 2, h * 3)).convert("1")
for y in range(h):
line = bytearray()
for x in range(w):
val = 0
for oy, l in enumerate(bits):
for ox, bi in enumerate(l):
if img.getpixel((x * 2 + ox, y * 3 + oy)):
val |= bi
2023-10-15 04:45:49 +03:00
# if img.getpixel((x * 2 + 1, y * 3 + 2)):
# val ^= 0x9f
2023-10-15 04:26:23 +03:00
line.append(val)
fp.write(line)
print(f"wrote {i + 1} / {len(argv) - 2}")