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