import struct
size = 5, 5
arr = [1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1,
    1, 0]
data = struct.pack('B' * len(arr), *[(pixel * 255) for pixel in arr])
img = Image.frombuffer('L', size, data)
img.save('image.png')
Binary List to PNG in Python