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