from PIL import Image width = 520 height = 256 img = Image.new('RGB', (width,height), (255,255,255)) text = open("decrypted.txt", "r") for i in range(250): line = text.readline() for j in range(510): if line[j] == 'x': img.putpixel((j, i), (0,0,0)) text.close() img = img.resize((width // 2, height)) img.save('decrypted.png')