字母驗證碼
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')