python整理二十一——用PIL生成验证码
2009-01-21 16:30
393 查看
python的PTL库,在图片处理方面太强大了,以前偶尔用过几次,最近弄个验证码玩玩:
代码逻辑很简单,瞄两眼就明白了……
def test(): import Image import ImageDraw import ImageFont import random import md5 dt = datetime.datetime.now() im, draw = None, None font = ImageFont.truetype('LCALLIG.TTF', 16) m_md5 = md5.new() m_md5.update( str(dt) ) rand_str = m_md5.hexdigest()[:4] im = Image.new('RGB', (60,30), '#000000') draw = ImageDraw.Draw(im) draw.text((10,5), rand_str, font=font) fpath = '%s.jpg' % rand_str fp = file(fpath, 'wb') im.save(fp,"JPEG") fp.close() if __name__ == '__main__': print test()
代码逻辑很简单,瞄两眼就明白了……
相关文章推荐
- Python使用PIL模块生成随机验证码
- Python图片处理PIL/pillow/生成验证码/出现KeyError: 和The _imagingft C module is not installed
- Python图片处理PIL/pillow/生成验证码/出现KeyError: 和The _imagingft C module is not installed
- Python图片处理PIL/pillow/生成验证码/出现KeyError: 和The _imagingft C module is not installed
- PIL(Python Image Library)生成验证码
- python使用PIL模块生成验证码
- 学习python:实例2.用PIL生成随机验证码
- python PIL模块与随机生成中文验证码
- python PIL模块与随机生成中文验证码
- PIL(Python Image Library)生成验证码
- Python: Window 64位 Python 使用PIL && 验证码生成
- Python学习常用第三方模块:PIL,生成验证码
- python+ PIL 生成验证码图片
- python生成验证码
- python生成验证码
- Python+Selenium+PIL+Tesseract自动识别验证码进行一键登录
- python 随机生成验证码
- 通过 Python + Python Imaging Library (PIL) 生成简单函数图像
- python 生成验证码
- python selenium+PIL+免验证码登陆