Copy the ComfyUI "Workflow" tag from png to another

Started by koalakoker, September 24, 2024, 01:22:55 PM

Previous topic - Next topic

koalakoker

Hello to everyone

I'm trying to explain my needs and issue because I'm pretty sure that I'll find here the solution.

I have one PNG file that has been generated by ComfyUI. Lets call original.png that has inside the meta tags that is needed lo reload the workflow (that are the project settings used to generate this image).

Effectively, checking with the exiftool, for the tags I see one of them that seems exactly it:

Workflow                        : {"last_node_id": 44, "last_link_id": 125, "nodes": [{"id": 22, "type": "BasicGuider", ... and so on, a long JSON data that represent, I think, the required settings.

When I elaborate the image I'll get a new image without these informations. Lets call reworked.png.

Now I want to copy these setting from the original image to this last one, but when I try to copy them with:

exiftool -tagsFromFile original.png -Workflow reworked.png

I receive this message:

Warning: Tag 'workflow' is not defined - original.png
Warning: No writable tags set from reworked.png
    0 image files updated
    1 image files unchanged

I tried also to copy all tags, but the one that I want to copy (workflow) is not copied.

Any hints to solve it?

Many thank in advance

Ciao
Koalakoker

StarGeek

As the error says, exiftool doesn't have a definition for Workflow, so it doesn't know the proper way to write it.

It's easy enough to add with a config file, though. I'm copy/pasting the PNG section from the example.config file and editing it to match the Stable Diffusion Parameters tag that was added recently. I'll also add Prompt which appears in my ComfyUI images.

# ComfyUI.config
# Config file for the workflow and prompt tags added by ComfyUI
# save this into a file called ComfyUI.config in the same directory as exiftool. You can then
# use this command to copy the tags
#    exiftool -config ComfyUI.config -TagsFromFile Source.Png -workflow -prompt Target.png
%Image::ExifTool::UserDefined = (
    'Image::ExifTool::PNG::TextualData' => {
        # Example 12.  PNG:NewPngTag1
        workflow => { %unreg }, # (written by ComfyUI)
        # Example 13.  PNG:NewPngTag2
        prompt => { %unreg }, # (written by ComfyUI)
    },
);
1;

The test file I copied to had the data in the correct place and format, but I haven't tested to see if you can drag/drop a copied file onto the ComfyUI interface to see if it works.


I've also noticed these tags in some SD files I've downloaded, but they seem uncommon and I don't know the source. But they probably can be added the same way as above if needed. There are also a couple of different tags I've seen that I think are added by AUTOMATIC1111, but I can't find a copy of them ATM.
smproj
parameters-json
postprocessing
extras
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

koalakoker

Thank you so much for your quick reply.  :)
It works perfectly, I also tried successfully to import the PNG file into ComfyUI and it recognizes it.

Now I tried to do the same using a .JPG file as destination but it doesn't work.

I also tried to manually adapt the .config file by substituting JPG instead of PNG, but maybe I did something wrong.

Would it be possible to do the same with a JPG file? (although I don't actually know if the ComfyUI interface could open it)

Anyway thanks anyway for your precious help.

Ciao
Koalakoker

Phil Harvey

Hi Koalakoker,

JPG images don't support PNG metadata.  You'll have to find out where this is stored in a JPG and make another definition in the config file for this tag.  Use this command on a JPG with the tag to see where it is stored:

exiftool -s -G1 FILE

Typically metadata in JPG images is stored in EXIF (IFD0 or ExifIFD) or XMP.  I'm guessing that XMP would be best, but if so I don't know why ComfyUI wouldn't also write it as XMP to the PNG since PNG also supports XMP.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

From the JPEGs I've seen, the prompts are usually saved in the EXIF:UserComment tag. But none of the JPEGs I've looked at include a workflow. I don't think workflow is saved in the JPEGs.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype