29 lines
795 B
Python
29 lines
795 B
Python
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(content: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=content,
|
|
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
|