From c4a8112b0cc9ae689a566f833d229da5b9703a03 Mon Sep 17 00:00:00 2001 From: dseditor Date: Sun, 4 Jan 2026 21:37:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E7=89=88=E5=9E=8BB=E6=96=87?= =?UTF-8?q?=E5=AD=97=E6=BA=A2=E5=87=BA=E4=B8=A6=E6=B7=BB=E5=8A=A0=E5=B0=81?= =?UTF-8?q?=E9=9D=A2=E6=8E=92=E7=89=88=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修正版型B故事頁的max_lines計算錯誤 - 移除錯誤的min/max邏輯,直接使用計算值 - 添加「關閉封面排版」功能 - 關閉時使用第一張圖片作為滿版封面(不含文字) - 修改預設輸出路徑為./ComfyUI/output/MyPDF/ - 符合ComfyUI將資料放在ComfyUI子資料夾的邏輯 --- photo_magazine_generator.py | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/photo_magazine_generator.py b/photo_magazine_generator.py index cc4f9dd..40aa8db 100644 --- a/photo_magazine_generator.py +++ b/photo_magazine_generator.py @@ -394,11 +394,15 @@ class PhotoMagazineMaker: "layout": (["版型A-經典排版", "版型B-藝術拼貼", "版型C-簡約現代"], {"default": "版型A-經典排版"}), "font": (font_files, {"default": font_files[0] if font_files else "default"}), "compress_pdf": ("BOOLEAN", {"default": False}), - "output_path": ("STRING", {"default": "./output/photo_magazine.pdf"}), + "disable_cover_layout": ("BOOLEAN", { + "default": False, + "tooltip": "關閉封面排版,使用第一張圖片作為滿版封面(不含文字)" + }), + "output_path": ("STRING", {"default": "./ComfyUI/output/MyPDF/photo_magazine.pdf"}), } } - INPUT_IS_LIST = (True, False, False, False, False, False, False) # 只有images是列表 + INPUT_IS_LIST = (True, False, False, False, False, False, False, False) # 只有images是列表 RETURN_TYPES = ("STRING",) RETURN_NAMES = ("result",) FUNCTION = "make_photo_magazine" @@ -1393,9 +1397,10 @@ class PhotoMagazineMaker: padding_bottom = 10*mm # 底部邊距(增加以確保不溢出) available_text_height = box_height - title_area_height - padding_bottom - # 計算最大可顯示行數(更保守的計算) + # 計算最大可顯示行數(直接使用計算值) max_lines = int(available_text_height / line_height) - max_lines = max(min(max_lines, len(content_lines)), 1) # 至少1行,最多實際行數 + if max_lines < 1: + max_lines = 1 # 至少顯示1行 # 起始Y位置 start_y = box_y + box_height - title_area_height @@ -1762,7 +1767,7 @@ class PhotoMagazineMaker: print(f"圖片分配結果: 封面={allocation['cover']}, 內頁={allocation['pages']}, 故事頁={allocation['story']}, 尾頁={allocation['footer']}") return allocation - def make_photo_magazine(self, images, json_data, template, layout, font, compress_pdf, output_path): + def make_photo_magazine(self, images, json_data, template, layout, font, compress_pdf, disable_cover_layout, output_path): """製作寫真雜誌""" try: # 根據ComfyUI規範,當INPUT_IS_LIST=True時,所有參數都是列表 @@ -1772,7 +1777,8 @@ class PhotoMagazineMaker: layout_name = layout[0] if isinstance(layout, list) and layout else "版型A-經典排版" font_name_input = font[0] if isinstance(font, list) and font else "default" compress_enabled = compress_pdf[0] if isinstance(compress_pdf, list) and compress_pdf else False - base_output = output_path[0] if isinstance(output_path, list) and output_path else "./output/photo_magazine.pdf" + disable_cover = disable_cover_layout[0] if isinstance(disable_cover_layout, list) and disable_cover_layout else False + base_output = output_path[0] if isinstance(output_path, list) and output_path else "./ComfyUI/output/MyPDF/photo_magazine.pdf" # 為檔案名添加時間戳記,防止覆蓋 import os.path @@ -1877,7 +1883,22 @@ class PhotoMagazineMaker: print("警告:JSON中缺少cover數據,使用預設值") cover_data = {"title": "寫真集", "subtitle": "", "description": ""} - self.draw_cover_page(c, magazine_data, cover_image, template_config, font_name, layout_name, compress_enabled) + # 檢查是否關閉封面排版 + if disable_cover: + # 關閉封面排版:使用第一張圖片作為滿版封面(不含文字) + print("✓ 關閉封面排版,使用第一張圖片作為滿版封面") + if cover_image: + # 創建滿版圖片 + full_bleed = self.create_full_bleed_image(cover_image, 210*mm, 297*mm) + c.drawImage(full_bleed, 0, 0, width=210*mm, height=297*mm, preserveAspectRatio=False) + else: + # 沒有圖片時使用純色背景 + c.setFillColor(HexColor(template_config["primary"])) + c.rect(0, 0, 210*mm, 297*mm, fill=1, stroke=0) + else: + # 正常封面排版 + self.draw_cover_page(c, magazine_data, cover_image, template_config, font_name, layout_name, compress_enabled) + c.showPage() print("封面繪製完成") @@ -1973,4 +1994,4 @@ NODE_DISPLAY_NAME_MAPPINGS = { "PhotoMagazinePromptGenerator": "📝 寫真雜誌提示詞注入器", "PhotoMagazineParser": "🔍 JSON → 提示詞列表", "PhotoMagazineMaker": "📄 寫真雜誌製作器" -} \ No newline at end of file +}