from PIL import Image

image = Image.open("cocotiers_s2.png")

width, height = image.size

image_rgb = image.convert("RGB")

s = ""
for y in range(4):
    for x in range(width):
        pixel = image_rgb.getpixel((x,y))
        s = s + str(pixel[0]%2) + str(pixel[1]%2) + str(pixel[2]%2)
print(s)
for i in range(len(s)//8):
    val = int(s[i*8+0])*128 + int(s[i*8+1])*64 + int(s[i*8+2])*32 + int(s[i*8+3])*16 + int(s[i*8+4])*8 + int(s[i*8+5])*4 + int(s[i*8+6])*2 + int(s[i*8+7])*1
    c = chr(val)
    print(c, end='')
