Skip to content

Commit 8285cc1

Browse files
committed
0011-0013 ok
1 parent d5f3389 commit 8285cc1

58 files changed

Lines changed: 212 additions & 3 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

burness/0010/image_verification.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#-*- coding: utf-8-*-
2+
3+
# Source:https://github.com/Show-Me-the-Code/show-me-the-code
4+
# Author:Burness Duan
5+
# Date:2014-12-29
6+
# Python 3.3
7+
8+
9+
import random
10+
import string
11+
from PIL import Image, ImageDraw, ImageFont, ImageFilter
12+
13+
14+
def random_string(y):
15+
'''
16+
生成指定长度的随机字符串
17+
'''
18+
return ''.join(random.choice(string.ascii_letters) for x in range(y))
19+
20+
21+
def create_verifi_image(strs,
22+
size=(120, 30),
23+
img_type = 'jpg',
24+
mode = 'RGB',
25+
bg_color= (255, 255, 255),
26+
fg_color = (0, 0, 255),
27+
font_size =18,
28+
font_type = 'ahronbd.ttf',
29+
draw_lines=True,
30+
n_line=(1, 2),
31+
draw_points=True,
32+
point_chance = 2,
33+
):
34+
35+
width, height = size
36+
img = Image.new(mode, size, bg_color)
37+
draw = ImageDraw.Draw(img)
38+
if draw_lines:
39+
line_num = random.randint(*n_line)
40+
for i in range(line_num):
41+
begin = (random.randint(0, size[0]), random.randint(0, size[1]))
42+
end = (random.randint(0, size[0]), random.randint(0, size[1]))
43+
draw.line([begin, end], fill=(0, 0, 0))
44+
45+
if draw_points:
46+
chance = min(100, max(0, int(point_chance)))
47+
for w in range(width):
48+
for h in range(height):
49+
tmp = random.randint(0,100)
50+
if tmp >100 -chance:
51+
draw.point((w,h),fill =(0,0,0))
52+
font = ImageFont.truetype(font_type, font_size)
53+
font_width, font_height = font.getsize(strs)
54+
draw.text(((width-font_width)/3,(height-font_height)/3),strs,font=font, fill=fg_color)
55+
params = [1 - float(random.randint(1, 2)) / 100, 0, 0, 0, 1 - float(random.randint(1, 10)) / 100,
56+
float(random.randint(1, 2)) / 500,
57+
0.001,
58+
float(random.randint(1, 2)) / 500
59+
]
60+
img = img.transform(size, Image.PERSPECTIVE, params)
61+
img = img.filter(ImageFilter.EDGE_ENHANCE_MORE)
62+
return img
63+
64+
65+
if __name__ == '__main__':
66+
strs = random_string(4)
67+
code_img = create_verifi_image(strs)
68+
code_img.show()
69+
code_img.save('validate.jpg')
70+
71+
72+
73+

burness/0010/validate.jpg

2.39 KB

burness/0011/filter_word.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#-*- coding: utf-8-*-
2+
3+
# Source:https://github.com/Show-Me-the-Code/show-me-the-code
4+
# Author:Burness Duan
5+
# Date:2014-12-29
6+
# Python 3.3
7+
8+
9+
def filter_word(input_word):
10+
input_word = input_word.split()
11+
filter_word_list = []
12+
with open('./filter_word.txt','r') as f:
13+
for content in f:
14+
# print content
15+
filter_word_list.append(content.strip('\n'))
16+
# print(filter_word_list)
17+
return filter_word_list
18+
19+
if __name__ == '__main__':
20+
input_words = input('Input some words')
21+
input_words_list = input_words.split()
22+
filter_word_list = filter_word(input_words)
23+
# print(filter_word_list)
24+
# print(input_words)
25+
# print(set(input_words_list).intersection(filter_word_list))
26+
if not set(input_words_list).intersection(filter_word_list):
27+
print('Human Rights')
28+
else:
29+
print('Freedom')
30+

burness/0011/filter_word.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
����
2+
����Ա
3+
����Ա
4+
�쵼
5+
ţ��
6+
ţ��
7+
����
8+
����
9+
love
10+
sex
11+
jiangge

burness/0012/filter_word.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
����
2+
����Ա
3+
����Ա
4+
�쵼
5+
ţ��
6+
ţ��
7+
����
8+
����
9+
love
10+
sex
11+
jiangge

burness/0012/filter_words_print.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#-*- coding: utf-8-*-
2+
3+
# Source:https://github.com/Show-Me-the-Code/show-me-the-code
4+
# Author:Burness Duan
5+
# Date:2014-12-29
6+
# Python 3.3
7+
8+
9+
def filter_word(input_word):
10+
input_word = input_word.split()
11+
filter_word_list = []
12+
with open('./filter_word.txt','r') as f:
13+
for content in f:
14+
filter_word_list.append(content.strip('\n'))
15+
return filter_word_list
16+
17+
if __name__ == '__main__':
18+
input_words = input('Input some words')
19+
input_words_list = input_words.split()
20+
filter_word_list = filter_word(input_words)
21+
22+
words_string=''
23+
for word in input_words_list:
24+
if word in filter_word_list:
25+
word = '*'*len(word)
26+
words_string += word + ' '
27+
print(words_string)
28+
29+

burness/0013/0.jpg

39.9 KB

burness/0013/1.jpg

36.1 KB

burness/0013/10.jpg

36.1 KB

burness/0013/11.jpg

31 KB

0 commit comments

Comments
 (0)