'''
This script will convert a 32x32 pixel image (either RGB or Indexed) to
"1"s (black) and "0"s (anything else) for saving on a EEPROM chip as a
coded message (see http://www.instructables.com/id/Message-in-a-Chip/).

You may need to install the PIL library from the command line using:
"pip install pillow"

March 2016
648.ken@gmail.com
'''

from PIL import Image

img_file = 'Bitmap_Template'
im = Image.open('%s.png' % img_file)

for y in range(32):
    row = []
    for x in range(32):
        a = im.getpixel((x, y))
        if im.mode == 'P':
            row.append(str(a))
        else:
            if a[1] == 255:
                row.append('1')
            else:
                row.append('0')   
    print('   %s,' % ', '.join(row))

im.close()
