加载图片并提取元数据信息 支持读取图片中的workflow、prompt、LoRA等参数信息
| 8 | |
| 9 | |
| 10 | class PD_LoadImageMetadata: |
| 11 | """ |
| 12 | 加载图片并提取元数据信息 |
| 13 | 支持读取图片中的workflow、prompt、LoRA等参数信息 |
| 14 | """ |
| 15 | |
| 16 | @classmethod |
| 17 | def INPUT_TYPES(s): |
| 18 | input_dir = folder_paths.get_input_directory() |
| 19 | files = [f for f in os.listdir(input_dir) if os.path.isfile(os.path.join(input_dir, f))] |
| 20 | files = folder_paths.filter_files_content_types(files, ["image"]) |
| 21 | return { |
| 22 | "required": { |
| 23 | "image": (sorted(files), {"image_upload": True}) |
| 24 | }, |
| 25 | } |
| 26 | |
| 27 | CATEGORY = "PD:load image" |
| 28 | |
| 29 | RETURN_TYPES = ("IMAGE", "MASK", "STRING", "STRING", "STRING") |
| 30 | RETURN_NAMES = ("图片", "遮罩", "提示词", "模型信息", "LoRA信息") |
| 31 | FUNCTION = "load_image_with_metadata" |
| 32 | |
| 33 | def extract_metadata(self, image_path): |
| 34 | """ |
| 35 | 提取图片的元数据信息 |
| 36 | |
| 37 | Args: |
| 38 | image_path: 图片路径 |
| 39 | |
| 40 | Returns: |
| 41 | tuple: (prompt_text, model_info, lora_info) |
| 42 | """ |
| 43 | try: |
| 44 | img = Image.open(image_path) |
| 45 | |
| 46 | # 初始化返回值 |
| 47 | prompt_text = "" |
| 48 | model_info = "" |
| 49 | lora_info = "" |
| 50 | |
| 51 | # 尝试从PNG info中提取信息 |
| 52 | if hasattr(img, 'info') and img.info: |
| 53 | info = img.info |
| 54 | |
| 55 | # 调试:打印所有可用的info键 |
| 56 | print(f"📝 PNG Info 键: {list(info.keys())}") |
| 57 | |
| 58 | # 优先从prompt字段提取 (ComfyUI格式) |
| 59 | if 'prompt' in info: |
| 60 | try: |
| 61 | prompt_data = json.loads(info['prompt']) |
| 62 | |
| 63 | # 提取各类信息 |
| 64 | lora_list = [] |
| 65 | model_list = [] |
| 66 | prompt_texts = [] |
| 67 |
nothing calls this directly
no outgoing calls
no test coverage detected