logitech-g13-badapple/pbm2lpbm.py

24 lines
562 B
Python

#!/usr/bin/env python3
import numpy as np
from PIL import Image
import subprocess
import os
directory = 'pbm/'
totalFrames = len(os.listdir(directory))
for i in range(totalFrames):
# Read pbm file and run it through pbm2lpbm
f = os.path.join(directory, str(i)+".pbm")
fi = open(f, 'rb')
p = subprocess.Popen("pbm2lpbm", stdin=subprocess.PIPE, stdout=subprocess.PIPE)
lpbmOut = p.communicate(input=fi.read())[0]
fi.close()
# Write out new lpbm file
fn = 'lpbm/' + str(i) + '.lpbm'
lpbmFile = open(fn, 'wb')
lpbmFile.write(lpbmOut)
lpbmFile.close()