#!/usr/bin/env python3
import numpy as np
from PIL import Image
import subprocess
import os

directory = 'pbm/'
# Load image and convert to '1' mode
#for filename in os.listdir(directory):
for i in range(7777):
	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()

	fn = 'lpbm/' + str(i) + '.lpbm'
	lpbmFile = open(fn, 'wb')
	lpbmFile.write(lpbmOut)
	lpbmFile.close()
