Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added JiYouMCC/0010/0010.GIF
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions JiYouMCC/0010/0010.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from PIL import ImageFont, Image, ImageDraw
import random


class YZMInfo:

def __init__(self, img, code):
self.img = img
self.code = code


def ygm(font_size=20, count_min=4, count_max=10, code_height=30,
string='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
font_color=['black', 'darkblue', 'darkred', 'darkgreen'],
font_family='arial.ttf'):
if count_max < count_min:
count_max = count_min
code_count = random.randrange(count_min, count_max)
background = (random.randrange(230, 255),
random.randrange(230, 255),
random.randrange(230, 255))
line_color = [(random.randrange(0, 255),
random.randrange(0, 255),
random.randrange(0, 255)),
(random.randrange(0, 255),
random.randrange(0, 255),
random.randrange(0, 255)),
(random.randrange(0, 255),
random.randrange(0, 255),
random.randrange(0, 255))]
img_width = (font_size + 1) * code_count
img_height = code_height + font_size
verify = ''
im = Image.new('RGB', (img_width, img_height), background)
draw = ImageDraw.Draw(im)
code = random.sample(string, code_count)
draw = ImageDraw.Draw(im)
for i in range(random.randrange(code_count / 2, code_count)):
xy = (random.randrange(0, img_width), random.randrange(0, img_height),
random.randrange(0, img_width), random.randrange(0, img_height))
draw.line(xy, fill=random.choice(line_color), width=1)
x = font_size / 2
for i in code:
y = random.randrange(0, code_height)
font = ImageFont.truetype(
font_family, font_size + random.randrange(-font_size/3, font_size/3))
draw.text((x, y), i, font=font, fill=random.choice(font_color))
x += font_size
verify += i
return YZMInfo(img=im, code=verify.upper())


info = ygm(font_size=16,
code_height=10,
string='#@%&$abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789')
info.img.save("0010.GIF")
print info.code
7 changes: 7 additions & 0 deletions JiYouMCC/0010/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
第 0010 题:使用 Python 生成类似于下图中的字母验证码图片

![字母验证码](https://camo.githubusercontent.com/f80e7aa0d43b3685657b4d329f2809a28c82e12a/687474703a2f2f692e696d6775722e636f6d2f615668626567562e6a7067)

成品效果

![](https://raw.githubusercontent.com/JiYouMCC/python/master/JiYouMCC/0010/0010.GIF)
Binary file added JiYouMCC/0010/arial.ttf
Binary file not shown.
2 changes: 1 addition & 1 deletion JiYouMCC/0013/0013.md → JiYouMCC/0013/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

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

百度贴吧上面格式绝对没有我老博客上那么老实,就将就下吧
百度贴吧上面格式绝对没有我老博客上那么老实,就将就下吧
2 changes: 1 addition & 1 deletion JiYouMCC/0014/0014.md → JiYouMCC/0014/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

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

![student.xls](https://camo.githubusercontent.com/18dea9401449e4ca894d40d55134d9c28083280d/687474703a2f2f692e696d6775722e636f6d2f6e50446c706d652e6a7067)
![student.xls](https://camo.githubusercontent.com/18dea9401449e4ca894d40d55134d9c28083280d/687474703a2f2f692e696d6775722e636f6d2f6e50446c706d652e6a7067)
2 changes: 1 addition & 1 deletion JiYouMCC/0015/0015.md → JiYouMCC/0015/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

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

![city.xls](https://camo.githubusercontent.com/61120377319bfe5520c9d73f51776f923d6bd3b7/687474703a2f2f692e696d6775722e636f6d2f724f4862557a672e706e67)
![city.xls](https://camo.githubusercontent.com/61120377319bfe5520c9d73f51776f923d6bd3b7/687474703a2f2f692e696d6775722e636f6d2f724f4862557a672e706e67)
2 changes: 1 addition & 1 deletion JiYouMCC/0016/0016.md → JiYouMCC/0016/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

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

![numbers.xls](https://camo.githubusercontent.com/60da4d596289212b517547ddcc2408bfc9f39087/687474703a2f2f692e696d6775722e636f6d2f69757a305062762e706e67)
![numbers.xls](https://camo.githubusercontent.com/60da4d596289212b517547ddcc2408bfc9f39087/687474703a2f2f692e696d6775722e636f6d2f69757a305062762e706e67)
2 changes: 1 addition & 1 deletion JiYouMCC/0023/0023.md → JiYouMCC/0023/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
第 0023 题: 使用 Python 的 Web 框架,做一个 Web 版本 留言簿 应用。
---------------------------------------

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

Expand Down
File renamed without changes.