-
Notifications
You must be signed in to change notification settings - Fork 0
/
0011oddEven.py
31 lines (27 loc) · 884 Bytes
/
0011oddEven.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
http://www.pythonchallenge.com/pc/return/5808.html
'''
# from PIL import Image
# import urllib.request as ur, io
# url = "http://www.pythonchallenge.com/pc/return/cave.jpg"
# mgr = ur.HTTPPasswordMgrWithDefaultRealm()
# mgr.add_password(None, url, 'huge', 'file')
# opener = ur.build_opener(ur.HTTPBasicAuthHandler(mgr))
# data = opener.open(url).read()
# im = Image.open(io.BytesIO(data))
from PIL import Image
im = Image.open('0011cave.jpg')
w, h = im.size
imgs = [Image.new(im.mode, (w // 2, h // 2)) for i in range(4)]
imgs_load = [i.load() for i in imgs]
org = im.load()
for i in range(w):
for j in range(h):
org_pos = (i, j)
new_pos = (i // 2, j // 2)
imgs_load[i % 2 + j % 2 * 2 ][new_pos] = org[org_pos]
for i in range(4):
imgs[i].show()
#[imgs[i].save('0011%d.png' % i) for i in range(4)]