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
|
|
|
|
|
2024-12-18 00:35:17 +08:00
|
|
|
def new_proma(content:str):
|
|
|
|
# 靠 版型在哪
|
2024-11-22 02:14:01 +08:00
|
|
|
img = Image.new(mode="RGB",
|
|
|
|
size=(PROMA_WIDTH, PROMA_HEIGHT),
|
2024-12-18 00:35:17 +08:00
|
|
|
color=(255, 255, 255))
|
2024-11-22 02:14:01 +08:00
|
|
|
|
|
|
|
font = ImageFont.truetype(PROMA_FONT, PROMA_FONTSIZE, encoding='utf-8')
|
|
|
|
|
|
|
|
draw:ImageDraw.ImageDraw = ImageDraw.Draw(img)
|
|
|
|
draw.text(xy=(0, 0),
|
2024-12-18 00:35:17 +08:00
|
|
|
text=content,
|
2024-11-22 02:14:01 +08:00
|
|
|
font=font,
|
|
|
|
fill=(0, 0, 0))
|
|
|
|
|
2024-12-18 00:35:17 +08:00
|
|
|
# 存檔
|
2024-11-22 02:14:01 +08:00
|
|
|
filename = TMP_DIR + hashlib.sha512( str(time.time()).encode() ).hexdigest() + ".jpg"
|
|
|
|
img.save(filename)
|
|
|
|
filename = os.path.abspath(filename)
|
|
|
|
|
2024-12-18 00:35:17 +08:00
|
|
|
return filename
|