From 7f8d9f8c0ceb9330487a92036d73adaf36eab66b Mon Sep 17 00:00:00 2001 From: jinye_huang Date: Thu, 24 Apr 2025 19:17:19 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E8=80=A6=E4=BA=86=E9=83=A8=E5=88=86?= =?UTF-8?q?=E7=A1=AC=E7=BC=96=E7=A0=81=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/posterGen.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/posterGen.py b/core/posterGen.py index 9243446..7cabf22 100644 --- a/core/posterGen.py +++ b/core/posterGen.py @@ -89,7 +89,8 @@ class PosterGenerator: # 海报计数器,用于控制添加边框的频率 self.poster_count = 0 - + self.default_font_path = os.path.join(self.font_dir, "华康海报体简.ttc") + def _initialize_text_backgrounds(self): """初始化文本框底图""" try: @@ -137,7 +138,7 @@ class PosterGenerator: """获取随机字体""" try: # 使用正确的字体目录 - font_dir = "/root/autodl-tmp/poster_baseboard_0403/font" + font_dir = self.font_dir # 获取所有支持的字体文件 font_files = [f for f in os.listdir(font_dir) @@ -408,7 +409,8 @@ class PosterGenerator: main_title_font_size = font.size if 'font' in locals() else 48 # 默认字体大小 # 使用固定字体 - specific_font_path = os.path.join("/root/autodl-tmp/poster_baseboard_0403/font", "华康海报体简.ttc") + specific_font_path = self.default_font_path + # specific_font_path = os.path.join(self.font_dir, "华康海报体简.ttc") if not os.path.isfile(specific_font_path): specific_font_path = font_path if 'font_path' in locals() else self._get_font_path() @@ -510,7 +512,7 @@ class PosterGenerator: ImageFont.truetype(font_path, size=1) # 先用小尺寸测试字体是否可用 except Exception as e: print(f"加载字体失败: {str(e)},使用默认字体") - font_path = os.path.join("/root/autodl-tmp/poster_baseboard_0403/font", "华康海报体简.ttc") + font_path = self.default_font_path return font_path