Last active
November 22, 2025 11:46
-
-
Save yowasou/4a8c2bfe24cb569fa3d2651bda891b58 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 出力ファイル名に使っているloraの名前と年月日を付与するスクリプト | |
| # webui\scriptsに設置してReload UIすると適用される | |
| import os | |
| from datetime import datetime | |
| import re | |
| import modules.script_callbacks as script_callbacks | |
| # グローバルで連番を管理 | |
| image_counter = 0 | |
| def filename_hook(params): | |
| global image_counter | |
| image_counter += 1 | |
| # ファイル拡張子 | |
| ext = ".webp" | |
| # 元の保存先フォルダ | |
| folder = os.path.dirname(params.filename) if hasattr(params, "filename") else "outputs" | |
| # 幅x高さを取得 | |
| if hasattr(params, "image") and params.image is not None: | |
| width, height = params.image.size | |
| else: | |
| width, height = 512, 512 # デフォルト値 | |
| # StableDiffusionProcessing オブジェクトから prompt を取得 | |
| prompt = getattr(params.p, "prompt", "") | |
| # LoRA名(プロンプトに含まれている場合) | |
| lora_names = re.findall(r"<lora:([^:>]+)", prompt) | |
| lora_part = "_".join(lora_names) if lora_names else "noLora" | |
| # 時分 | |
| timestamp = datetime.now().strftime("%H%M") | |
| # ファイル名生成 | |
| filename_only = f"{width}x{height}_{lora_part}_{timestamp}_{image_counter}{ext}" | |
| params.filename = os.path.join(folder, filename_only) | |
| # コールバック登録 | |
| script_callbacks.on_before_image_saved(filename_hook) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
「幅x高さ_LoRA_時分_連番」を出すように修正。バッチ実行すると上書きされてしまう不具合を修正