Archive for September 17, 2007

Python Challenge level 11: “odd even”

Level 11 requires playing with images once again.

Fact 1: the image cave.jpg seems to have half ot its pixels blanked
We’ll assume odd and even pixels belong to different images. This snippet will put me out of my misery and let me know ;)

import Image
src = Image.open("cave.jpg")
w,h = src.size[0], src.size[1]
print "Image info:",src.format, src.size, src.mode
new = Image.new(src.mode,(w//2, h))

for i in range(w*h):
    y, x = divmod(i, w)
    p = src.getpixel((x,y))
    if i%2: #even==info, odd==photo
        new.putpixel((x/2,y/2+h//2),p)
    else:
        new.putpixel((x/2,y/2),p)
new.save('11.jpg')

Now it’s readable. “evil“. Next is Level 12.

Read the rest of this entry »