feat(group_horse_racing): 增加赛马消息图片渲染功能
- 在配置中新增图片渲染相关参数:RACE_RENDER_AS_IMAGE、RACE_IMAGE_WIDTH 等 - 复用 danding_qqpush 的 ImageRenderer,使其支持自定义标题 - 在比赛开始、结束和进度播报时,将文本消息转换为带标题的图片发送 - 修复测试用例中的消息发送函数调用
This commit is contained in:
@@ -117,7 +117,7 @@ class ImageRenderer:
|
||||
|
||||
return lines
|
||||
|
||||
def render(self, text: str) -> bytes:
|
||||
def render(self, text: str, title: str = "蛋定助手通知您:") -> bytes:
|
||||
"""
|
||||
将文本渲染为图片
|
||||
|
||||
@@ -148,7 +148,6 @@ class ImageRenderer:
|
||||
total_line_height = int(line_height * self.line_spacing)
|
||||
|
||||
# 标题相关
|
||||
title = "蛋定助手通知您:"
|
||||
title_font_size = int(self.font_size * 1.3) # 标题字体放大1.3倍
|
||||
title_font = self._load_font_by_size(title_font_size)
|
||||
title_height = int(line_height * 1.5) # 标题区域高度
|
||||
@@ -192,7 +191,7 @@ class ImageRenderer:
|
||||
|
||||
return img_byte_arr.getvalue()
|
||||
|
||||
def render_to_base64(self, text: str) -> str:
|
||||
def render_to_base64(self, text: str, title: str = "蛋定助手通知您:") -> str:
|
||||
"""
|
||||
将文本渲染为图片并返回 base64 编码
|
||||
|
||||
@@ -202,6 +201,6 @@ class ImageRenderer:
|
||||
Returns:
|
||||
base64 编码的图片数据
|
||||
"""
|
||||
img_bytes = self.render(text)
|
||||
img_bytes = self.render(text, title=title)
|
||||
base64_str = base64.b64encode(img_bytes).decode('utf-8')
|
||||
return f"base64://{base64_str}"
|
||||
|
||||
Reference in New Issue
Block a user