#!/usr/bin/env python

import Image
import sys

input = Image.open(sys.argv[1])
output = input.convert("RGB")

# yep, you have to guess or count these!
width = 46
height = 360

pw, ph = input.size

pixel_width = float(pw) / float(width)
pixel_height = float(ph) / float(height)

colour_red = (255, 0, 0)
for y in range(height):
    lineout = ''
    for x in range(width):
        px = output.getpixel((int(pixel_width * (0.5+x)), int(pixel_height * (0.5+y))))
        output.putpixel((int(pixel_width * (0.5+x)), int(pixel_height * (0.5+y))), colour_red)
        if px[0] > 128:
            lineout += "1"
        else:
            lineout += "0"
    print lineout

# show which pixels we sampled
output.show()
