niming_igapi/ig/ctxPictuterProma.py

26 lines
769 B
Python
Raw Normal View History

2024-11-22 02:14:01 +08:00
import time
import hashlib
import os
from PIL import Image, ImageDraw, ImageFont
from utils.const import PROMA_HEIGHT, PROMA_WIDTH, PROMA_FONT, PROMA_FONTSIZE, TMP_DIR
def new_proma(ctx:str):
img = Image.new(mode="RGB",
size=(PROMA_WIDTH, PROMA_HEIGHT),
color=(255, 255, 255)) # 靠 沒版型阿
font = ImageFont.truetype(PROMA_FONT, PROMA_FONTSIZE, encoding='utf-8')
draw:ImageDraw.ImageDraw = ImageDraw.Draw(img)
draw.text(xy=(0, 0),
text=ctx,
font=font,
fill=(0, 0, 0))
filename = TMP_DIR + hashlib.sha512( str(time.time()).encode() ).hexdigest() + ".jpg"
img.save(filename)
filename = os.path.abspath(filename)
return filename