Copy Metadata, from Pic A to B.
I'm a ComfyUI user, and often only five or six out of a hundred generated images meet my requirements. If the images are upscaled before I select them, it's a waste of resources and time. Therefore, I always use external tools to upscale the images after I've selected them, but this corrupts the metadata.
After trying various tools and nodes, I decided to create my own tool with a very simple function: copy and paste metadata.
How to use:
1. Specify an Original folder with PNG/WEBP/JPG image files containing metadata. These are usually the unupscaled image from "Save Image with Metadata".
2. Specify an Upscaled folder with images that have been upscaled using external tools (such as Final2x).
3. Specify an Output directory.
Since images upscaled by external tools are usually named with some text added before the filename, the program will automatically find the file with the "most similar name" in the Original folder, copy and paste the metadata, then place the final file in the Output directory.
Program defaults(auto mode):
1. If the metadata contains a complete workflow, the Upscaled image is in PNG format, the entire full metadata will be copied unconditionally.
2. For other cases, the program will attempt to copy the full metadata, but if the metadata is too large(over 60KB), it will instead copy the lite version(A1111 format string) of the metadata with auto mode. In Civital, the lite version of the metadata can still be correctly recognized, but it does not contain complete workflow data.
Description
Aboout V3.4 (The following content is AI's self-praise; how much you believe is up to you.):
1. Added JPG and WebP Image Format Support
Multi-format bidirectional compatibility: Previously only PNG format was supported, now both Original and Upscaled formats fully support JPG, JPEG, and WebP formats.
EXIF Writing Technology: For JPG and WebP images, standard EXIF UserComment writing technology is used to ensure that metadata is correctly embedded in non-PNG format images.
2. Deep Integration of External JSON Files
Automatic Sidecar Detection: During batch processing, if images in the Original directory do not contain embedded metadata, the program will automatically look for a .json file with the same name in the same directory as the metadata source.
Manual Toolbox (New in GUI Interface):
- Export Metadata as JSON: Can export complete metadata (including workflow) from a specified image into a separate JSON file.
- Inject JSON into Images: Can directly write manually specified JSON files (workflow or A1111 format) into a specified image.
3. ComfyUI Standard Workflow Bidirectional Compatibility (Lossless Encapsulation)
Standard JSON Export: The JSON file exported from the image now has a root directory structure that is completely consistent with ComfyUI's native .json workflow archive (containing nodes and links). The exported JSON file can be directly dragged into the ComfyUI workspace to load into the workflow, eliminating the problem of unreadable characters (\").
Civitai Field Invisible Encapsulation: Other fields required by Civitai (such as Prompt, Parameters, Author, etc.) are automatically and losslessly encapsulated in the extra.civitai_tool_metadata field and automatically restored when images are re-injected, achieving perfect bidirectional compatibility.
4. Unique "Automatic Metadata Rescue and Repair Engine" (for advanced ComfyUI nodes)
Additional Components for Advanced Loaders: When you use advanced custom nodes such as UNETLoader (separate model loader) or Power Lora Loader (rgthree) to generate images in ComfyUI, the A1111 parameter block output by the native ComfyUI will have a defect of missing Model and LoRA information.
- Automatic Workflow Detection: During batch processing or injection, the program now automatically parses the underlying workflow, extracts the actual Model filenames and enabled LoRAs, and formats them as Model: <model name> and <lora:name:weight>. It automatically concatenates and fills in the parameters block, significantly improving the Civitai platform's automatic recognition rate of advanced workflow image resources.
- However, it's not perfect. Some third-party custom nodes have inherent defects in metadata output. The output metadata itself does not contain enough information, which may cause Civitai to be unable to recognize it. This is beyond the limits of this tool.
5. EXIF Size Safety Protection and Degradation Mechanism
Smart Capacity Protection: JPG and WebP EXIF blocks have a physical limit of 65,535 bytes. The new version introduces a safe capacity detection and truncation mechanism:
Auto Mode: If the complete workflow exceeds the limit, it will automatically degrade to Lite mode, writing only parameters, to prevent image corruption or write failure.
Truncation Protection: Boundary strings are safely truncated to UTF-16 byte lengths, ensuring the program remains stable and does not crash even in extreme conditions.
