91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 5.54MB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發布日期: 2023-09-23
  • 語言: Python
  • 標簽: Python??

資源簡介

利用Python生成驗證碼圖片 代碼和字體文件壓縮包

資源截圖

代碼片段和文件信息

#?導入庫文件
from?PIL?import?ImageImageFontImageDrawImageFilter
import?stringrandomos


#?方法:獲得四個隨機字母
def?getRandomChar():
return?[random.choice(string.ascii_letters)for?_?in?range(4)]

#?方法:獲取隨機顏色
def?getRandomColor():
return?(random.randint(30100)random.randint(30100)random.randint(30100))

#?主方法:獲取驗證碼圖片
def?getCodePicture(fontPathoutPath):
#?圖片寬高
width?=?240
height?=?60
#?創建空白畫布
image?=?Image.new(‘RGB‘(widthheight)(180180180))
#?驗證碼字體
font?=?ImageFont.truetype(fontPath40)
#?畫出畫布,獲取畫布對象
draw?=?ImageDraw.Draw(image)
#?創建驗證碼對象
code?=?getRandomChar()
#?把驗證碼畫到畫布上
for?x?in?range(4):
draw.text((60*x+100)code[x]font=fontfill=getRandomColor())
#?填充噪點
for?_?in?range(random.randint(15003000)):
draw.point((random.randint(0width)random.randint(0height))fill?=?getRandomColor())
#?模糊處理
image?=?image.filter(ImageFilter.BLUR)
#?保存
image.save(outPath+“\\“+““.join(code)+“.jpg“‘jpeg‘)

if?__name__?==?‘__main__‘:
getCodePicture(“simsun.ttf“os.getcwd())



?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????1217??2017-07-14?17:21??codepicture.py
?????文件????10499104??2012-05-14?11:30??simsun.ttf

評論

共有 條評論