From 4aa55127c6291c2d81597771273bb6bd62c3347e Mon Sep 17 00:00:00 2001 From: jinye_huang Date: Wed, 14 May 2025 10:04:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E6=97=B6=E5=81=9C=E6=AD=A2=E4=BA=86?= =?UTF-8?q?=E8=B4=B4=E7=BA=B8=E6=A8=A1=E5=9D=97=E7=9A=84=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/poster_gen.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/core/poster_gen.py b/core/poster_gen.py index e8e9437..4c256ec 100644 --- a/core/poster_gen.py +++ b/core/poster_gen.py @@ -125,7 +125,6 @@ class PosterGenerator: def _initialize_stickers(self): """初始化贴纸素材""" - stickers = [] try: sticker_files = [f for f in os.listdir(self.sticker_dir) if f.endswith(('.png'))] print(f"找到贴纸素材: {sticker_files}") @@ -684,13 +683,14 @@ class PosterGenerator: # 获取海报尺寸 width, height = poster_image.size - # 决定是否添加贴纸(50%概率) - if random.random() < 0.5: + # 决定是否添加贴纸(25%概率添加) + if random.random() < 0.75: print("随机决定不添加贴纸") return poster_image # 随机决定添加1-3个贴纸 - sticker_count = random.randint(1, 3) + sticker_count = 1 + # sticker_count = random.randint(1, 3) print(f"准备添加 {sticker_count} 个贴纸") # 创建一个新图层用于合成 @@ -794,9 +794,10 @@ class PosterGenerator: final_poster.alpha_composite(text_layer) # (可选) 添加贴纸 - final_poster = self.add_stickers(final_poster) - print("Layers composed.") + # final_poster = self.add_stickers(final_poster) + # print("Layers composed.") + # 转换回 RGB 以保存为 JPG/PNG (移除 alpha通道) final_poster_rgb = final_poster.convert("RGB")