Skip to content

Commit 89593aa

Browse files
committed
Merge pull request Show-Me-the-Code#67 from JiYouMCC/master
Add 0010, update md files
2 parents 9ecb11b + 8226d53 commit 89593aa

File tree

10 files changed

+69
-5
lines changed

10 files changed

+69
-5
lines changed

JiYouMCC/0010/0010.GIF

3.28 KB
Loading

JiYouMCC/0010/0010.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from PIL import ImageFont, Image, ImageDraw
2+
import random
3+
4+
5+
class YZMInfo:
6+
7+
def __init__(self, img, code):
8+
self.img = img
9+
self.code = code
10+
11+
12+
def ygm(font_size=20, count_min=4, count_max=10, code_height=30,
13+
string='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
14+
font_color=['black', 'darkblue', 'darkred', 'darkgreen'],
15+
font_family='arial.ttf'):
16+
if count_max < count_min:
17+
count_max = count_min
18+
code_count = random.randrange(count_min, count_max)
19+
background = (random.randrange(230, 255),
20+
random.randrange(230, 255),
21+
random.randrange(230, 255))
22+
line_color = [(random.randrange(0, 255),
23+
random.randrange(0, 255),
24+
random.randrange(0, 255)),
25+
(random.randrange(0, 255),
26+
random.randrange(0, 255),
27+
random.randrange(0, 255)),
28+
(random.randrange(0, 255),
29+
random.randrange(0, 255),
30+
random.randrange(0, 255))]
31+
img_width = (font_size + 1) * code_count
32+
img_height = code_height + font_size
33+
verify = ''
34+
im = Image.new('RGB', (img_width, img_height), background)
35+
draw = ImageDraw.Draw(im)
36+
code = random.sample(string, code_count)
37+
draw = ImageDraw.Draw(im)
38+
for i in range(random.randrange(code_count / 2, code_count)):
39+
xy = (random.randrange(0, img_width), random.randrange(0, img_height),
40+
random.randrange(0, img_width), random.randrange(0, img_height))
41+
draw.line(xy, fill=random.choice(line_color), width=1)
42+
x = font_size / 2
43+
for i in code:
44+
y = random.randrange(0, code_height)
45+
font = ImageFont.truetype(
46+
font_family, font_size + random.randrange(-font_size/3, font_size/3))
47+
draw.text((x, y), i, font=font, fill=random.choice(font_color))
48+
x += font_size
49+
verify += i
50+
return YZMInfo(img=im, code=verify.upper())
51+
52+
53+
info = ygm(font_size=16,
54+
code_height=10,
55+
string='#@%&$abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789')
56+
info.img.save("0010.GIF")
57+
print info.code

JiYouMCC/0010/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
第 0010 题:使用 Python 生成类似于下图中的字母验证码图片
2+
3+
![字母验证码](https://camo.githubusercontent.com/f80e7aa0d43b3685657b4d329f2809a28c82e12a/687474703a2f2f692e696d6775722e636f6d2f615668626567562e6a7067)
4+
5+
成品效果
6+
7+
![](https://raw.githubusercontent.com/JiYouMCC/python/master/JiYouMCC/0010/0010.GIF)

JiYouMCC/0010/arial.ttf

754 KB
Binary file not shown.

JiYouMCC/0013/0013.md renamed to JiYouMCC/0013/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66

77
我很懒惰没用啥爬虫架构请无视..
88

9-
百度贴吧上面格式绝对没有我老博客上那么老实,就将就下吧
9+
百度贴吧上面格式绝对没有我老博客上那么老实,就将就下吧

JiYouMCC/0014/0014.md renamed to JiYouMCC/0014/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010

1111
请将上述内容写到 student.xls 文件中,如下图所示:
1212

13-
![student.xls](https://camo.githubusercontent.com/18dea9401449e4ca894d40d55134d9c28083280d/687474703a2f2f692e696d6775722e636f6d2f6e50446c706d652e6a7067)
13+
![student.xls](https://camo.githubusercontent.com/18dea9401449e4ca894d40d55134d9c28083280d/687474703a2f2f692e696d6775722e636f6d2f6e50446c706d652e6a7067)

JiYouMCC/0015/0015.md renamed to JiYouMCC/0015/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
请将上述内容写到 city.xls 文件中,如下图所示:
1010

11-
![city.xls](https://camo.githubusercontent.com/61120377319bfe5520c9d73f51776f923d6bd3b7/687474703a2f2f692e696d6775722e636f6d2f724f4862557a672e706e67)
11+
![city.xls](https://camo.githubusercontent.com/61120377319bfe5520c9d73f51776f923d6bd3b7/687474703a2f2f692e696d6775722e636f6d2f724f4862557a672e706e67)

JiYouMCC/0016/0016.md renamed to JiYouMCC/0016/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
请将上述内容写到 numbers.xls 文件中,如下图所示:
1010

11-
![numbers.xls](https://camo.githubusercontent.com/60da4d596289212b517547ddcc2408bfc9f39087/687474703a2f2f692e696d6775722e636f6d2f69757a305062762e706e67)
11+
![numbers.xls](https://camo.githubusercontent.com/60da4d596289212b517547ddcc2408bfc9f39087/687474703a2f2f692e696d6775722e636f6d2f69757a305062762e706e67)

JiYouMCC/0023/0023.md renamed to JiYouMCC/0023/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
第 0023 题: 使用 Python 的 Web 框架,做一个 Web 版本 留言簿 应用。
22
---------------------------------------
33

4-
以前在sea上弄过一个差不多的:http://jillyou.sinaapp.com/guest/
4+
以前在sea上弄过一个差不多的:http://www.jithee.name/guestbook/
55
不过sea弄django syncdb比较痛苦,所有sql拼接出的
66
直接django真够傻瓜的……
77

File renamed without changes.

0 commit comments

Comments
 (0)