From 5ecf55869ba912fd1dbe18cf2da5617be1f86f89 Mon Sep 17 00:00:00 2001 From: KimigaiiWuyi <444835641@qq.com> Date: Wed, 30 Aug 2023 01:48:30 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E9=83=A8?= =?UTF-8?q?=E5=88=86Pillow=E7=89=88=E6=9C=AC=E9=80=82=E9=85=8D=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GenshinUID/genshinuid_ann/ann_card.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/GenshinUID/genshinuid_ann/ann_card.py b/GenshinUID/genshinuid_ann/ann_card.py index b3634266..0a3e48f1 100644 --- a/GenshinUID/genshinuid_ann/ann_card.py +++ b/GenshinUID/genshinuid_ann/ann_card.py @@ -148,7 +148,12 @@ async def ann_detail_card(ann_id): draw.text((x, y), duanluo, fill=(0, 0, 0), font=gs_font_26) y += drow_line_height * line_count - _x, _y = gs_font_26.getsize('囗') + if hasattr(gs_font_26, 'getsize'): + _x, _y = gs_font_26.getsize('囗') # type: ignore + else: + bbox = gs_font_26.getbbox('囗') + _x, _y = bbox[2] - bbox[0], bbox[3] - bbox[1] + padding = (_x, _y, _x, _y) im = ImageOps.expand(im, padding, '#f9f6f2') @@ -183,7 +188,8 @@ def get_duanluo(text: str): # 行高 line_height = 0 for char in text: - width, height = draw.textsize(char, gs_font_26) + left, top, right, bottom = draw.textbbox((0, 0), char, gs_font_26) + width, height = (right - left, bottom - top) sum_width += width if sum_width > max_width: # 超过预设宽度就修改段落 以及当前行数 line_count += 1