Extension on the example of BasicWolf:
from PIL import Image 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')
I think this is what you need ...
source share