第八题地址:http://www.pythonchallenge.com/pc/def/oxygen.html
打开地址我们只看到一张图片,照旧去检查网页中的HTML内的提示,我们只看到一个oxygen.png是可能的提示。更改地址并下载图片。发现可以的地方就是图片中不和谐的灰色渐变条,搜索后发现可能要用到Python Imaging Library - PIL库来对图片进行分析。
对于win32, 可以很容易从 http://www.pythonware.com/products/pil/ 处下载到需要的对应PIL库,但是对于有些win64的使用者,为了大家方便,可以去如下地址下载PIL库
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pil
需要注意的是,使用这个库之后,你要导入类似Image模块的时候,不是简单的import Image,而是必须使用from PIL import Image才可以正常使用。
准备就绪,我们来分析oxygen.png
from PIL import Image
import re
i = Image.open('C:\Python27\oxygen.png')
row = []
for x in range(0, i.size[0]):
row.append(i.getpixel((x, 43)))
print row
我们得到图片,发现是629*95的大小。灰色的条纹基本在中间,我们测试42,43,44,45,46... 43-46得到的是一样的结果。
[(115, 115, 115, 255), (115, 115, 115, 255), (115, 115, 115, 255), (115, 115, 115, 255), (115, 115, 115, 255), (109, 109, 109, 255), (109, 109, 109, 255), (109, 109, 109, 255), (109, 109, 109, 255), (109, 109, 109, 255), (109, 109, 109, 255), (109, 109, 109, 255), (97, 97, 97, 255), (97, 97, 97, 255), (97, 97, 97, 255), (97, 97, 97, 255), (97, 97, 97, 255), (97, 97, 97, 255), (97, 97, 97, 255), (114, 114, 114, 255), (114, 114, 114, 255), (114, 114, 114, 255), (114, 114, 114, 255), (114, 114, 114, 255), (114, 114, 114, 255), (114, 114, 114, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (103, 103, 103, 255), (103, 103, 103, 255), (103, 103, 103, 255), (103, 103, 103, 255), (103, 103, 103, 255), (103, 103, 103, 255), (103, 103, 103, 255), (117, 117, 117, 255), (117, 117, 117, 255), (117, 117, 117, 255), (117, 117, 117, 255), (117, 117, 117, 255), (117, 117, 117, 255), (117, 117, 117, 255), (121, 121, 121, 255), (121, 121, 121, 255), (121, 121, 121, 255), (121, 121, 121, 255), (121, 121, 121, 255), (121, 121, 121, 255), (121, 121, 121, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (121, 121, 121, 255), (121, 121, 121, 255), (121, 121, 121, 255), (121, 121, 121, 255), (121, 121, 121, 255), (121, 121, 121, 255), (121, 121, 121, 255), (111, 111, 111, 255), (111, 111, 111, 255), (111, 111, 111, 255), (111, 111, 111, 255), (111, 111, 111, 255), (111, 111, 111, 255), (111, 111, 111, 255), (117, 117, 117, 255), (117, 117, 117, 255), (117, 117, 117, 255), (117, 117, 117, 255), (117, 117, 117, 255), (117, 117, 117, 255), (117, 117, 117, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (109, 109, 109, 255), (109, 109, 109, 255), (109, 109, 109, 255), (109, 109, 109, 255), (109, 109, 109, 255), (109, 109, 109, 255), (109, 109, 109, 255), (97, 97, 97, 255), (97, 97, 97, 255), (97, 97, 97, 255), (97, 97, 97, 255), (97, 97, 97, 255), (97, 97, 97, 255), (97, 97, 97, 255), (100, 100, 100, 255), (100, 100, 100, 255), (100, 100, 100, 255), (100, 100, 100, 255), (100, 100, 100, 255), (100, 100, 100, 255), (100, 100, 100, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (105, 105, 105, 255), (105, 105, 105, 255), (105, 105, 105, 255), (105, 105, 105, 255), (105, 105, 105, 255), (105, 105, 105, 255), (105, 105, 105, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (46, 46, 46, 255), (46, 46, 46, 255), (46, 46, 46, 255), (46, 46, 46, 255), (46, 46, 46, 255), (46, 46, 46, 255), (46, 46, 46, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (104, 104, 104, 255), (104, 104, 104, 255), (104, 104, 104, 255), (104, 104, 104, 255), (104, 104, 104, 255), (104, 104, 104, 255), (104, 104, 104, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (110, 110, 110, 255), (110, 110, 110, 255), (110, 110, 110, 255), (110, 110, 110, 255), (110, 110, 110, 255), (110, 110, 110, 255), (110, 110, 110, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (120, 120, 120, 255), (120, 120, 120, 255), (120, 120, 120, 255), (120, 120, 120, 255), (120, 120, 120, 255), (120, 120, 120, 255), (120, 120, 120, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (108, 108, 108, 255), (108, 108, 108, 255), (108, 108, 108, 255), (108, 108, 108, 255), (108, 108, 108, 255), (108, 108, 108, 255), (108, 108, 108, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (118, 118, 118, 255), (118, 118, 118, 255), (118, 118, 118, 255), (118, 118, 118, 255), (118, 118, 118, 255), (118, 118, 118, 255), (118, 118, 118, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (108, 108, 108, 255), (108, 108, 108, 255), (108, 108, 108, 255), (108, 108, 108, 255), (108, 108, 108, 255), (108, 108, 108, 255), (108, 108, 108, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (105, 105, 105, 255), (105, 105, 105, 255), (105, 105, 105, 255), (105, 105, 105, 255), (105, 105, 105, 255), (105, 105, 105, 255), (105, 105, 105, 255), (115, 115, 115, 255), (115, 115, 115, 255), (115, 115, 115, 255), (115, 115, 115, 255), (115, 115, 115, 255), (115, 115, 115, 255), (115, 115, 115, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (91, 91, 91, 255), (91, 91, 91, 255), (91, 91, 91, 255), (91, 91, 91, 255), (91, 91, 91, 255), (91, 91, 91, 255), (91, 91, 91, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (53, 53, 53, 255), (53, 53, 53, 255), (53, 53, 53, 255), (53, 53, 53, 255), (53, 53, 53, 255), (53, 53, 53, 255), (53, 53, 53, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (54, 54, 54, 255), (54, 54, 54, 255), (54, 54, 54, 255), (54, 54, 54, 255), (54, 54, 54, 255), (54, 54, 54, 255), (54, 54, 54, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (51, 51, 51, 255), (51, 51, 51, 255), (51, 51, 51, 255), (51, 51, 51, 255), (51, 51, 51, 255), (51, 51, 51, 255), (51, 51, 51, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (52, 52, 52, 255), (52, 52, 52, 255), (52, 52, 52, 255), (52, 52, 52, 255), (52, 52, 52, 255), (52, 52, 52, 255), (52, 52, 52, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (53, 53, 53, 255), (53, 53, 53, 255), (53, 53, 53, 255), (53, 53, 53, 255), (53, 53, 53, 255), (53, 53, 53, 255), (53, 53, 53, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (54, 54, 54, 255), (54, 54, 54, 255), (54, 54, 54, 255), (54, 54, 54, 255), (54, 54, 54, 255), (54, 54, 54, 255), (54, 54, 54, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (50, 50, 50, 255), (50, 50, 50, 255), (50, 50, 50, 255), (50, 50, 50, 255), (50, 50, 50, 255), (50, 50, 50, 255), (50, 50, 50, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (93, 93, 93, 255), (93, 93, 93, 255), (93, 93, 93, 255), (93, 93, 93, 255), (93, 93, 93, 255), (93, 93, 93, 255), (93, 93, 93, 255), (93, 93, 93, 255), (65, 47, 1, 255), (117, 99, 49, 255), (132, 116, 65, 255), (110, 93, 47, 255), (129, 116, 71, 255), (112, 105, 53, 255), (113, 106, 54, 255), (161, 145, 96, 255), (148, 126, 79, 255), (147, 118, 74, 255), (166, 137, 97, 255), (143, 118, 88, 255), (85, 61, 33, 255), (83, 59, 25, 255), (97, 71, 34, 255), (107, 79, 42, 255), (106, 78, 41, 255), (109, 84, 44, 255), (98, 73, 32, 255), (103, 74, 32, 255), (94, 62, 21, 255)]
如此多的结果,应该不是我们需要的,不过继续解析下去。因为中间的那条灰色,对于一个图像模式为RGBA的图片来说,每个像素都是一个四元组,前3个分量分别是红色(R),绿色(G),蓝色(B),对于灰度来说,R==B==G
from PIL import Image
import re
i = Image.open('C:\Python27\oxygen.png')
row = []
for x in range(0, i.size[0]):
row.append(i.getpixel((x, 43)))
print row
ords = []
for r, g, b, a in row:
if r == g == b:
ords.append(r)
print ords
得到结果如下
[(115, 115, 115, 255), (115, 115, 115, 255), (115, 115, 115, 255), (115, 115, 115, 255), (115, 115, 115, 255), (109, 109, 109, 255), (109, 109, 109, 255), (109, 109, 109, 255), (109, 109, 109, 255), (109, 109, 109, 255), (109, 109, 109, 255), (109, 109, 109, 255), (97, 97, 97, 255), (97, 97, 97, 255), (97, 97, 97, 255), (97, 97, 97, 255), (97, 97, 97, 255), (97, 97, 97, 255), (97, 97, 97, 255), (114, 114, 114, 255), (114, 114, 114, 255), (114, 114, 114, 255), (114, 114, 114, 255), (114, 114, 114, 255), (114, 114, 114, 255), (114, 114, 114, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (103, 103, 103, 255), (103, 103, 103, 255), (103, 103, 103, 255), (103, 103, 103, 255), (103, 103, 103, 255), (103, 103, 103, 255), (103, 103, 103, 255), (117, 117, 117, 255), (117, 117, 117, 255), (117, 117, 117, 255), (117, 117, 117, 255), (117, 117, 117, 255), (117, 117, 117, 255), (117, 117, 117, 255), (121, 121, 121, 255), (121, 121, 121, 255), (121, 121, 121, 255), (121, 121, 121, 255), (121, 121, 121, 255), (121, 121, 121, 255), (121, 121, 121, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (121, 121, 121, 255), (121, 121, 121, 255), (121, 121, 121, 255), (121, 121, 121, 255), (121, 121, 121, 255), (121, 121, 121, 255), (121, 121, 121, 255), (111, 111, 111, 255), (111, 111, 111, 255), (111, 111, 111, 255), (111, 111, 111, 255), (111, 111, 111, 255), (111, 111, 111, 255), (111, 111, 111, 255), (117, 117, 117, 255), (117, 117, 117, 255), (117, 117, 117, 255), (117, 117, 117, 255), (117, 117, 117, 255), (117, 117, 117, 255), (117, 117, 117, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (109, 109, 109, 255), (109, 109, 109, 255), (109, 109, 109, 255), (109, 109, 109, 255), (109, 109, 109, 255), (109, 109, 109, 255), (109, 109, 109, 255), (97, 97, 97, 255), (97, 97, 97, 255), (97, 97, 97, 255), (97, 97, 97, 255), (97, 97, 97, 255), (97, 97, 97, 255), (97, 97, 97, 255), (100, 100, 100, 255), (100, 100, 100, 255), (100, 100, 100, 255), (100, 100, 100, 255), (100, 100, 100, 255), (100, 100, 100, 255), (100, 100, 100, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (105, 105, 105, 255), (105, 105, 105, 255), (105, 105, 105, 255), (105, 105, 105, 255), (105, 105, 105, 255), (105, 105, 105, 255), (105, 105, 105, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (46, 46, 46, 255), (46, 46, 46, 255), (46, 46, 46, 255), (46, 46, 46, 255), (46, 46, 46, 255), (46, 46, 46, 255), (46, 46, 46, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (104, 104, 104, 255), (104, 104, 104, 255), (104, 104, 104, 255), (104, 104, 104, 255), (104, 104, 104, 255), (104, 104, 104, 255), (104, 104, 104, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (110, 110, 110, 255), (110, 110, 110, 255), (110, 110, 110, 255), (110, 110, 110, 255), (110, 110, 110, 255), (110, 110, 110, 255), (110, 110, 110, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (120, 120, 120, 255), (120, 120, 120, 255), (120, 120, 120, 255), (120, 120, 120, 255), (120, 120, 120, 255), (120, 120, 120, 255), (120, 120, 120, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (116, 116, 116, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (108, 108, 108, 255), (108, 108, 108, 255), (108, 108, 108, 255), (108, 108, 108, 255), (108, 108, 108, 255), (108, 108, 108, 255), (108, 108, 108, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (118, 118, 118, 255), (118, 118, 118, 255), (118, 118, 118, 255), (118, 118, 118, 255), (118, 118, 118, 255), (118, 118, 118, 255), (118, 118, 118, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (101, 101, 101, 255), (108, 108, 108, 255), (108, 108, 108, 255), (108, 108, 108, 255), (108, 108, 108, 255), (108, 108, 108, 255), (108, 108, 108, 255), (108, 108, 108, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (105, 105, 105, 255), (105, 105, 105, 255), (105, 105, 105, 255), (105, 105, 105, 255), (105, 105, 105, 255), (105, 105, 105, 255), (105, 105, 105, 255), (115, 115, 115, 255), (115, 115, 115, 255), (115, 115, 115, 255), (115, 115, 115, 255), (115, 115, 115, 255), (115, 115, 115, 255), (115, 115, 115, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (91, 91, 91, 255), (91, 91, 91, 255), (91, 91, 91, 255), (91, 91, 91, 255), (91, 91, 91, 255), (91, 91, 91, 255), (91, 91, 91, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (53, 53, 53, 255), (53, 53, 53, 255), (53, 53, 53, 255), (53, 53, 53, 255), (53, 53, 53, 255), (53, 53, 53, 255), (53, 53, 53, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (54, 54, 54, 255), (54, 54, 54, 255), (54, 54, 54, 255), (54, 54, 54, 255), (54, 54, 54, 255), (54, 54, 54, 255), (54, 54, 54, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (51, 51, 51, 255), (51, 51, 51, 255), (51, 51, 51, 255), (51, 51, 51, 255), (51, 51, 51, 255), (51, 51, 51, 255), (51, 51, 51, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (52, 52, 52, 255), (52, 52, 52, 255), (52, 52, 52, 255), (52, 52, 52, 255), (52, 52, 52, 255), (52, 52, 52, 255), (52, 52, 52, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (48, 48, 48, 255), (53, 53, 53, 255), (53, 53, 53, 255), (53, 53, 53, 255), (53, 53, 53, 255), (53, 53, 53, 255), (53, 53, 53, 255), (53, 53, 53, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (54, 54, 54, 255), (54, 54, 54, 255), (54, 54, 54, 255), (54, 54, 54, 255), (54, 54, 54, 255), (54, 54, 54, 255), (54, 54, 54, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (44, 44, 44, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (32, 32, 32, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (50, 50, 50, 255), (50, 50, 50, 255), (50, 50, 50, 255), (50, 50, 50, 255), (50, 50, 50, 255), (50, 50, 50, 255), (50, 50, 50, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (49, 49, 49, 255), (93, 93, 93, 255), (93, 93, 93, 255), (93, 93, 93, 255), (93, 93, 93, 255), (93, 93, 93, 255), (93, 93, 93, 255), (93, 93, 93, 255), (93, 93, 93, 255), (65, 47, 1, 255), (117, 99, 49, 255), (132, 116, 65, 255), (110, 93, 47, 255), (129, 116, 71, 255), (112, 105, 53, 255), (113, 106, 54, 255), (161, 145, 96, 255), (148, 126, 79, 255), (147, 118, 74, 255), (166, 137, 97, 255), (143, 118, 88, 255), (85, 61, 33, 255), (83, 59, 25, 255), (97, 71, 34, 255), (107, 79, 42, 255), (106, 78, 41, 255), (109, 84, 44, 255), (98, 73, 32, 255), (103, 74, 32, 255), (94, 62, 21, 255)]
[115, 115, 115, 115, 115, 109, 109, 109, 109, 109, 109, 109, 97, 97, 97, 97, 97, 97, 97, 114, 114, 114, 114, 114, 114, 114, 116, 116, 116, 116, 116, 116, 116, 32, 32, 32, 32, 32, 32, 32, 103, 103, 103, 103, 103, 103, 103, 117, 117, 117, 117, 117, 117, 117, 121, 121, 121, 121, 121, 121, 121, 44, 44, 44, 44, 44, 44, 44, 32, 32, 32, 32, 32, 32, 32, 121, 121, 121, 121, 121, 121, 121, 111, 111, 111, 111, 111, 111, 111, 117, 117, 117, 117, 117, 117, 117, 32, 32, 32, 32, 32, 32, 32, 109, 109, 109, 109, 109, 109, 109, 97, 97, 97, 97, 97, 97, 97, 100, 100, 100, 100, 100, 100, 100, 101, 101, 101, 101, 101, 101, 101, 32, 32, 32, 32, 32, 32, 32, 105, 105, 105, 105, 105, 105, 105, 116, 116, 116, 116, 116, 116, 116, 46, 46, 46, 46, 46, 46, 46, 32, 32, 32, 32, 32, 32, 32, 116, 116, 116, 116, 116, 116, 116, 104, 104, 104, 104, 104, 104, 104, 101, 101, 101, 101, 101, 101, 101, 32, 32, 32, 32, 32, 32, 32, 110, 110, 110, 110, 110, 110, 110, 101, 101, 101, 101, 101, 101, 101, 120, 120, 120, 120, 120, 120, 120, 116, 116, 116, 116, 116, 116, 116, 32, 32, 32, 32, 32, 32, 32, 108, 108, 108, 108, 108, 108, 108, 101, 101, 101, 101, 101, 101, 101, 118, 118, 118, 118, 118, 118, 118, 101, 101, 101, 101, 101, 101, 101, 108, 108, 108, 108, 108, 108, 108, 32, 32, 32, 32, 32, 32, 32, 105, 105, 105, 105, 105, 105, 105, 115, 115, 115, 115, 115, 115, 115, 32, 32, 32, 32, 32, 32, 32, 91, 91, 91, 91, 91, 91, 91, 49, 49, 49, 49, 49, 49, 49, 48, 48, 48, 48, 48, 48, 48, 53, 53, 53, 53, 53, 53, 53, 44, 44, 44, 44, 44, 44, 44, 32, 32, 32, 32, 32, 32, 32, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 48, 48, 48, 48, 48, 48, 48, 44, 44, 44, 44, 44, 44, 44, 32, 32, 32, 32, 32, 32, 32, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 54, 54, 54, 54, 54, 54, 54, 44, 44, 44, 44, 44, 44, 44, 32, 32, 32, 32, 32, 32, 32, 49, 49, 49, 49, 49, 49, 49, 48, 48, 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49, 49, 44, 44, 44, 44, 44, 44, 44, 32, 32, 32, 32, 32, 32, 32, 49, 49, 49, 49, 49, 49, 49, 48, 48, 48, 48, 48, 48, 48, 51, 51, 51, 51, 51, 51, 51, 44, 44, 44, 44, 44, 44, 44, 32, 32, 32, 32, 32, 32, 32, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 52, 52, 52, 52, 52, 52, 52, 44, 44, 44, 44, 44, 44, 44, 32, 32, 32, 32, 32, 32, 32, 49, 49, 49, 49, 49, 49, 49, 48, 48, 48, 48, 48, 48, 48, 53, 53, 53, 53, 53, 53, 53, 44, 44, 44, 44, 44, 44, 44, 32, 32, 32, 32, 32, 32, 32, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 54, 54, 54, 54, 54, 54, 54, 44, 44, 44, 44, 44, 44, 44, 32, 32, 32, 32, 32, 32, 32, 49, 49, 49, 49, 49, 49, 49, 50, 50, 50, 50, 50, 50, 50, 49, 49, 49, 49, 49, 49, 49, 93, 93, 93, 93, 93, 93, 93, 93]
我们得到都是数字,尝试按照ASCII码转换为chr来显示输出。
print map(chr, ords)
结果
['s', 's', 's', 's', 's', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 't', 't', 't', 't', 't', 't', 't', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'g', 'g', 'g', 'g', 'g', 'g', 'g', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'y', 'y', 'y', 'y', 'y', 'y', 'y', ',', ',', ',', ',', ',', ',', ',', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'u', 'u', 'u', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'e', 'e', 'e', 'e', 'e', 'e', 'e', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 't', 't', 't', 't', 't', 't', 't', '.', '.', '.', '.', '.', '.', '.', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 't', 't', 't', 't', 't', 't', 't', 'h', 'h', 'h', 'h', 'h', 'h', 'h', 'e', 'e', 'e', 'e', 'e', 'e', 'e', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 't', 't', 't', 't', 't', 't', 't', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'l', 'l', 'l', 'l', 'l', 'l', 'l', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'v', 'v', 'v', 'v', 'v', 'v', 'v', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'l', 'l', 'l', 'l', 'l', 'l', 'l', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 's', 's', 's', 's', 's', 's', 's', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '[', '[', '[', '[', '[', '[', '[', '1', '1', '1', '1', '1', '1', '1', '0', '0', '0', '0', '0', '0', '0', '5', '5', '5', '5', '5', '5', '5', ',', ',', ',', ',', ',', ',', ',', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '0', '0', '0', '0', '0', '0', '0', ',', ',', ',', ',', ',', ',', ',', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '6', '6', '6', '6', '6', '6', '6', ',', ',', ',', ',', ',', ',', ',', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', '1', '1', '1', '1', '1', '1', '0', '0', '0', '0', '0', '0', '0', '1', '1', '1', '1', '1', '1', '1', ',', ',', ',', ',', ',', ',', ',', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', '1', '1', '1', '1', '1', '1', '0', '0', '0', '0', '0', '0', '0', '3', '3', '3', '3', '3', '3', '3', ',', ',', ',', ',', ',', ',', ',', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '4', '4', '4', '4', '4', '4', '4', ',', ',', ',', ',', ',', ',', ',', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', '1', '1', '1', '1', '1', '1', '0', '0', '0', '0', '0', '0', '0', '5', '5', '5', '5', '5', '5', '5', ',', ',', ',', ',', ',', ',', ',', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '6', '6', '6', '6', '6', '6', '6', ',', ',', ',', ',', ',', ',', ',', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', '1', '1', '1', '1', '1', '1', '2', '2', '2', '2', '2', '2', '2', '1', '1', '1', '1', '1', '1', '1', ']', ']', ']', ']', ']', ']', ']', ']']
我们试着讲他们合起来
print "".join(map(chr, ords))
结果
sssssmmmmmmmaaaaaaarrrrrrrttttttt ggggggguuuuuuuyyyyyyy,,,,,,, yyyyyyyooooooouuuuuuu mmmmmmmaaaaaaadddddddeeeeeee iiiiiiittttttt....... ttttttthhhhhhheeeeeee nnnnnnneeeeeeexxxxxxxttttttt llllllleeeeeeevvvvvvveeeeeeelllllll iiiiiiisssssss [[[[[[[111111100000005555555,,,,,,, 111111111111110000000,,,,,,, 111111111111116666666,,,,,,, 111111100000001111111,,,,,,, 111111100000003333333,,,,,,, 111111111111114444444,,,,,,, 111111100000005555555,,,,,,, 111111111111116666666,,,,,,, 111111122222221111111]]]]]]]]
好了。这下应该能看出来,有些英文单词在里面,比如smart,guy,you,the。。。
数了一下,除了第一个s之外,都是7个字母重复。所以我们重新修改之前的for loop,每次跳7个字符来进行loop。
from PIL import Image
import re
i = Image.open('C:\Python27\oxygen.png')
row = []
for x in range(0, i.size[0], 7):
row.append(i.getpixel((x, 43)))
print row
ords = []
for r, g, b, a in row:
if r == g == b:
ords.append(r)
print ords
print map(chr, ords)
print "".join(map(chr, ords))
这下得到的新结果
[(115, 115, 115, 255), (109, 109, 109, 255), (97, 97, 97, 255), (114, 114, 114, 255), (116, 116, 116, 255), (32, 32, 32, 255), (103, 103, 103, 255), (117, 117, 117, 255), (121, 121, 121, 255), (44, 44, 44, 255), (32, 32, 32, 255), (121, 121, 121, 255), (111, 111, 111, 255), (117, 117, 117, 255), (32, 32, 32, 255), (109, 109, 109, 255), (97, 97, 97, 255), (100, 100, 100, 255), (101, 101, 101, 255), (32, 32, 32, 255), (105, 105, 105, 255), (116, 116, 116, 255), (46, 46, 46, 255), (32, 32, 32, 255), (116, 116, 116, 255), (104, 104, 104, 255), (101, 101, 101, 255), (32, 32, 32, 255), (110, 110, 110, 255), (101, 101, 101, 255), (120, 120, 120, 255), (116, 116, 116, 255), (32, 32, 32, 255), (108, 108, 108, 255), (101, 101, 101, 255), (118, 118, 118, 255), (101, 101, 101, 255), (108, 108, 108, 255), (32, 32, 32, 255), (105, 105, 105, 255), (115, 115, 115, 255), (32, 32, 32, 255), (91, 91, 91, 255), (49, 49, 49, 255), (48, 48, 48, 255), (53, 53, 53, 255), (44, 44, 44, 255), (32, 32, 32, 255), (49, 49, 49, 255), (49, 49, 49, 255), (48, 48, 48, 255), (44, 44, 44, 255), (32, 32, 32, 255), (49, 49, 49, 255), (49, 49, 49, 255), (54, 54, 54, 255), (44, 44, 44, 255), (32, 32, 32, 255), (49, 49, 49, 255), (48, 48, 48, 255), (49, 49, 49, 255), (44, 44, 44, 255), (32, 32, 32, 255), (49, 49, 49, 255), (48, 48, 48, 255), (51, 51, 51, 255), (44, 44, 44, 255), (32, 32, 32, 255), (49, 49, 49, 255), (49, 49, 49, 255), (52, 52, 52, 255), (44, 44, 44, 255), (32, 32, 32, 255), (49, 49, 49, 255), (48, 48, 48, 255), (53, 53, 53, 255), (44, 44, 44, 255), (32, 32, 32, 255), (49, 49, 49, 255), (49, 49, 49, 255), (54, 54, 54, 255), (44, 44, 44, 255), (32, 32, 32, 255), (49, 49, 49, 255), (50, 50, 50, 255), (49, 49, 49, 255), (93, 93, 93, 255), (117, 99, 49, 255), (148, 126, 79, 255), (107, 79, 42, 255)]
[115, 109, 97, 114, 116, 32, 103, 117, 121, 44, 32, 121, 111, 117, 32, 109, 97, 100, 101, 32, 105, 116, 46, 32, 116, 104, 101, 32, 110, 101, 120, 116, 32, 108, 101, 118, 101, 108, 32, 105, 115, 32, 91, 49, 48, 53, 44, 32, 49, 49, 48, 44, 32, 49, 49, 54, 44, 32, 49, 48, 49, 44, 32, 49, 48, 51, 44, 32, 49, 49, 52, 44, 32, 49, 48, 53, 44, 32, 49, 49, 54, 44, 32, 49, 50, 49, 93]
['s', 'm', 'a', 'r', 't', ' ', 'g', 'u', 'y', ',', ' ', 'y', 'o', 'u', ' ', 'm', 'a', 'd', 'e', ' ', 'i', 't', '.', ' ', 't', 'h', 'e', ' ', 'n', 'e', 'x', 't', ' ', 'l', 'e', 'v', 'e', 'l', ' ', 'i', 's', ' ', '[', '1', '0', '5', ',', ' ', '1', '1', '0', ',', ' ', '1', '1', '6', ',', ' ', '1', '0', '1', ',', ' ', '1', '0', '3', ',', ' ', '1', '1', '4', ',', ' ', '1', '0', '5', ',', ' ', '1', '1', '6', ',', ' ', '1', '2', '1', ']']
smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]
最下面的那句话,我们得到一个新的线索。就是继续根据ASCII码的原则,把数字转换为字符。
print "".join(map(chr, map(int, re.findall("\d+", "".join(map(chr, ords))))))
最终得到通关的密码
integrity
####################################################################################################################################
Python Imaging Library - PIL
1. 转换图档格式
类似于影像处理一样,PIL支持图片文档格式的转换。
<pre name="code" class="python">i = Image.open('C:\Python27\oxygen.png')
print i.format, i.size, i.mode
# result
PNG (629, 95) RGBA
图片的格式放在format属性里,尺寸放在size属性里,color space颜色模式放在mode属性里。所以,我们能确定上面题目中的文件是RGBA模式的。
可以用save方法,再把图片存为其他格式,save方法也可以指定格式。 不指定格式的时候,会自动判断。
i.save('new.png', JPEG)
只是处理一两个图片文档的时候,用python直译器比较合适。然而处理一大群文档的时候,就用程序比较方便
from glob import glob
from os.path import splitext
from PIL import Image
jpglist = glob( "python_imaging_pix/*.[jJ][pP][gG]" )
for jpg in jpglist:
im = Image.open(jpg)
png = splitext(jpg)[0]+".png"
im.save(png)
print png
然后结果就是只要有*.jpg或者*.JPG就会变成.png格式。
根据存档格式的不同,save方法还提供了不同的选项参数。比如JPEG而言,可以接受quality(从1到100的整数,预设为75),optimize(True/False)以及progression(True/False)
i.save( "quality100.jpg", quality=100 )
2. 改变图片以及制作缩略图
PIL提供了resize方法,用来执行图像的缩放。
i = Image.open('C:\Python27\oxygen.png')
width = 4
height = 4
r = i.resize((width, height), Image.BILINEAR)
print r.size
# result
(4, 4)
resize方法会传回一个新的Image对象,同时旧的Image不会被改动。resize接受两个参数,第一个用于改变指定的大小,是一个双元素的tuple的参数,分别表示宽和高。第二个参数可以省略,是用来指定方法使用的时候的内插法,预设是Image.NEAREST(取最近的点),Image.BILINEAR是高品质。
rotate方法, 用于图片的旋转。传入两个参数,第一个是逆时针的度数,第二个也是内插法,可以省略。
<pre name="code" class="python">r= i.rotate( 45, Image.BILINEAR )
同样的,rotate不会改变原来图片的尺寸。但是,因为不会改变尺寸,所以有时候会出现黑边。所以如果需要连尺寸一起改变,需要改用transpose方法。
r= i.transpose( Image.ROTATE_90 )
transpose方法接受Image.FLIP_LEFT_RIGHT, Image.FLIP_TOP_DOWN, ROTATE_90, ROTATE_180, ROTATE_270等五种参数。后三种是旋转均为逆时针。
rotate方法会对像素进行内插,而transpose则只是转换像素,所以没有内插设定,也不会印象图片文档的品质。
thumbnail方法,在接受宽和高的尺寸的时候,和resize有不同。resize允许我们进行不等比例的缩放,但是thumbnail仅仅允许等比例的缩放,并且以宽,高中小的那一个作为标准。
from PIL import Image
i = Image.open('C:\Python27\oxygen.png')
width = 400
height = 400
i.thumbnail((width, height))
i.save('thumbnail.jpg')
print i.size
# result
(400, 60)
3. 修改图片文档的内容
PIL可以完成贴图的功能。
from PIL import Image
baseim = Image.open('C:\Python27\oxygen.png')
floatim = Image.open( "thumbnail.jpg" )
baseim.paste( floatim, (150, 50) )
baseim.save( "pasted.jpg" )
利用paste方法,可以把图片黏贴在一起。
paste方法需要两个参数,第一个是需要贴上去的image,第二个参数是贴上的位置。
第二个参数的三种指定方式:
* None:不指定位置与尺寸,那么paste会假设要贴上的image与被贴上的尺寸完全相同。
* (left,upper):双元素tuple,会把图片贴在左上角对齐的位置。
* (left,upper,right,lower):四元素tuple,除了会把图片左上角对齐之外,也会对齐右下角。感觉和第一类尺寸相同是一个道理。
处理能够贴图,还可以裁剪。
from PIL import Image
im = Image.open('C:\Python27\oxygen.png')
nim = im.crop((90,10,680,80))
nim.thumbnail((400,400))
nim.save("croped.jpg")
在使用crop方法的时候,需要注意的是传入参数的顺序,已经大小。tuple参数的顺序是left,upper,right,lower,所以要注意后面大于前面。
此外,PIL还有滤镜的功能filter,用于处理特效。这些滤镜都放在ImageFilter模组里面。
from PIL import Image
from PIL import ImageFilter
im = Image.open('C:\Python27\oxygen.png')
nim = im
for i in range(20):
nim = nim.filter(ImageFilter.BLUR)
nim.save("blured.jpg")
上述代码,意思是虚化20次。
滤镜的基本语法是 newim = im.filter(ImageFilter.FILTERNAME)
FILTERNAME ,就是类似我们用的BLUR,还有CONTOUR, DETAIL, EDGE_ENHANCE, EDGE_ENHANCE_MORE, EMBOSS, FIND_EDGES, SMOOTH, SMOOTH_MORE, SHARPEN等等。利用滤镜可以进行特效处理等。
4. 用PIL制作新的图片文档
PIL中的ImageDraw模块提供我们制作新的图片文档的功能。
from PIL import Image
from PIL import ImageDraw
im = Image.new('RGB', (400, 300))
draw = ImageDraw.Draw(im)
im.save('test.jpg')
我们会得到一个黑色的图片文档。
draw提供了arc() (弧線)、chord() (弦)、line() (線段)、ellipse() (橢圓)、point() (點)、rectangle() (矩形) 與 polygon() (多邊形)。
ImageFont模块,提供了如何写入文字的功能。
from PIL import Image
from PIL import ImageDraw
# from PIL import ImageFont
im = Image.new('RGB', (400, 300))
draw = ImageDraw.Draw(im)
# font = ImageFont.truetype("/usr/share/fonts/truetype/freefont/FreeMono.ttf", 24)
draw.text( (20,20), "TEXT")
im.save('test.jpg')
用ImageFont的truetype方法建立一个TureType字型,第一个参数是字型的路径,第二个参数是大小。写字的方法用text方法来完成,接受两个参数,分别是文字的位置,左上角的点,和文字的具体内容,另外还可以用font选项来指定字型,不指定就是预设。
如果我们想写两串相同的,但是大小不一样的字,那么可以如下操作:
largefont = ImageFont.truetype("/usr/share/fonts/truetype/freefont/FreeMono.ttf", 48 )
smallfont = ImageFont.truetype("/usr/share/fonts/truetype/freefont/FreeMono.ttf", 24 )
im = Image.new( "RBG", (400,300) )
draw = ImageDraw.Draw( im )
draw.text( (20,20), "SmallTEXT", font=smallfont )
draw.text( (20,120), "LargeTEXT", font=largefont )
draw.ink = 0 + 255*256 + 0*256*256
以上會把畫筆設成綠色。ink 值必須要是一個整數,其值由色彩的 RGB 值算出。舉幾個 ink 值的例子:
- 紅色的 ink 值應設為 255(R) + 0(G)*256 + 0(B)*256*256,
- 藍色的 ink 值應設為 0(R) + 0(G)*256 + 255(B)*256*256,
- 靛色的 ink 值應設為 0(R) + 255(G)*256 + 255(B)*256*256
参考:
http://www.blogjava.net/Skynet/archive/2009/11/28/303986.html
http://stackoverflow.com/questions/1076638/trouble-using-python-pil-library-to-crop-and-save-image
http://www.nowamagic.net/librarys/veda/detail/2606http://www.nowamagic.net/librarys/veda/detail/2606
http://abruzzi.iteye.com/blog/314790