MCPcopy Create free account
hub / github.com/7BEII/Comfyui_PDuse / PD_LoadImageMetadata

Class PD_LoadImageMetadata

py/Load_ImageMetadata.py:10–280  ·  view source on GitHub ↗

加载图片并提取元数据信息 支持读取图片中的workflow、prompt、LoRA等参数信息

Source from the content-addressed store, hash-verified

8
9
10class 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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected