pythonchallenge_level11

level11

地址:http://www.pythonchallenge.com/pc/return/5808.html
源码:git@code.aliyun.com:qianlizhixing12/PythonChallenge.git。
问题:根据提示找出重叠的图片。

#!/usr/bin/env python3
# -*- coding:UTF-8 -*-

# Level 11
import os
import urllib.request

filename = "cave.jpg"
url = "http://www.pythonchallenge.com/pc/return/" + filename
userinfo = {"realm":"inflate", "uri":url, "user":"huge", "passwd":"file"}
# create a password manager
password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
# Add the username and password
password_mgr.add_password(**userinfo)
# create "opener" (OpenerDirector instance)
handler = urllib.request.HTTPBasicAuthHandler(password_mgr)
# create "opener" (OpenerDirector instance)
opener = urllib.request.build_opener(handler)
# Install the opener.all calls to urllib.request.urlopen use our opener.
urllib.request.install_opener(opener)

response = urllib.request.urlopen(url)
body = response.read()
response.close

if os.path.exists(filename): os.remove(filename)
tmpjpg= open(filename, "wb")
tmpjpg.write(body)
tmpjpg.close()

import PIL.Image

srcimg = PIL.Image.open(filename)
desimg = PIL.Image.new(srcimg.mode, srcimg.size)
for w in range(0, srcimg.size[0], 2):
    for h in range(0, srcimg.size[1], 2):
        desimg.putpixel((w, h), srcimg.getpixel((w, h)))
desimg.show()

if os.path.exists(filename): os.remove(filename)
上一篇:pythonchallenge_level0


下一篇:从摩托罗拉、诺基亚再到航空领域应用,这款开源数据库的成功如何成就天才程序员?