This commit is contained in:
@ -29,8 +29,8 @@ def text_to_transparent_image(text, font_size=40, padding=0, text_color=(0, 0, 0
|
||||
text_height = bbox[3] - bbox[1]
|
||||
|
||||
# 计算图像大小(文本大小 + 内边距)
|
||||
image_width = text_width + 2 * padding
|
||||
image_height = text_height + 2 * padding
|
||||
image_width = int(text_width + 2 * padding)
|
||||
image_height = int(text_height + 2 * padding)
|
||||
|
||||
# 创建RGBA模式的空白图像(带透明通道)
|
||||
image = Image.new('RGBA', (image_width, image_height), (0, 0, 0, 0))
|
||||
@ -177,7 +177,7 @@ async def generate_dice_image(number: int) -> BytesIO:
|
||||
], dtype=np.float32)
|
||||
|
||||
# 加载背景图像,保留透明通道
|
||||
background = cv2.imread(ASSETS / "template.png", cv2.IMREAD_UNCHANGED)
|
||||
background = cv2.imread(str(ASSETS / "template.png"), cv2.IMREAD_UNCHANGED)
|
||||
|
||||
|
||||
# 对文本图像进行3D变换(保持透明通道)
|
||||
@ -189,7 +189,7 @@ async def generate_dice_image(number: int) -> BytesIO:
|
||||
|
||||
pil_final = Image.fromarray(final_image_simple)
|
||||
# 导入一系列图像
|
||||
images = [Image.open(ASSETS / f"{i}.png") for i in range(1, 12)]
|
||||
images: list[Image.Image] = [Image.open(ASSETS / f"{i}.png") for i in range(1, 12)]
|
||||
images.append(pil_final)
|
||||
frame_durations = [100] * (len(images) - 1) + [100000]
|
||||
# 保存为BytesIO对象
|
||||
|
||||
Reference in New Issue
Block a user