驗證碼

字母驗證碼
import os
from tkinter import Image


def gen_vcode(request):
    #1- 創建畫布
    image = Image.new('RGB',(100,50),(100,20,30))

    #2- 創建畫筆
    draw = ImageDraw.Draw(image,'RGB')

    #3- 字體樣式
    font_path = os.path.join(BASE_DIR,'App/static/fonts/balabala')
    font = Image.truetype(font_path,30)

    #4- 畫
    draw.text((30,10),'M',font=font,fill=(200,200,200))

    #5- 轉化成圖片
    buff = io.BytesIO()
    image.save(buff,'png')
    return HttpResponse(buff.getvalue(),'image/png')
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章