I don't know a thing about PIL and I haven't used Python for some time, but here is my take at this bits to bytes conversion problem.
import itertools
# assuming that `bits` is your array of bits (0 or 1)
# ordered from LSB to MSB in consecutive bytes they represent
# e.g. bits = [0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1] will give you bytes = [128,255]
bytes = [sum([byte[b] << b for b in range(0,8)])
for byte in zip(*(iter(bits),) * 8)
]
# warning! if len(bits) % 8 != 0, then these last bits will be lost
This code should be mostly self-explanatory.