修复首次签到时使用道具后签到报错

This commit is contained in:
HibiKier
2023-03-20 21:23:04 +08:00
parent 99cf2b32b1
commit fac1d4bff9
3 changed files with 19 additions and 19 deletions
+7 -2
View File
@@ -456,7 +456,7 @@ class BuildImage:
说明:
在图片上添加文字
参数:
:param pos: 文字位置
:param pos: 文字位置(使用center_type中的center后会失效,使用by_width后x失效,使用by_height后y失效)
:param text: 文字内容
:param fill: 文字颜色
:param center_type: 居中类型,可能的值 center: 完全居中,by_width: 水平居中,by_height: 垂直居中
@@ -469,7 +469,12 @@ class BuildImage:
"center_type must be 'center', 'by_width' or 'by_height'"
)
w, h = self.w, self.h
ttf_w, ttf_h = self.getsize(text)
longgest_text = ''
sentence = text.split("\n")
for x in sentence:
longgest_text = x if len(x) > len(longgest_text) else longgest_text
ttf_w, ttf_h = self.getsize(longgest_text)
ttf_h = ttf_h * len(sentence)
if center_type == "center":
w = int((w - ttf_w) / 2)
h = int((h - ttf_h) / 2)