Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webp loader fix #3415

Closed
wants to merge 3 commits into from
Closed

Conversation

audioscavenger
Copy link

This is the way to generate the type 2 exif tag 37510, that is seeked for in pnginfo.js

    exif = img.getexif()
    dump = json.dumps(metadata)
    exif[ExifTags.Base.UserComment] = json.dumps(metadata)
    exif_dat = exif.tobytes()
    img.save(image_path, exif=exif_dat)

In doing so, you cannot import this escaped json string, the way pnginfo reads it. pnginfo now parses it and send it ready to consume to app.js. also there is no txt_chunks, there will always, only will be 1 single exif tag with the whole prompt.
app.js is also modified to reflect this fix.
Tested and working.
Once you accept this patch, I will also PR you the jpeg import addon.
thank you!

This is the way to generate the type 2 exif tag 37510 that you want to import json from a webp/jpeg:
```
    exif = img.getexif()
    dump = json.dumps(metadata)
    exif[ExifTags.Base.UserComment] = json.dumps(metadata)
    exif_dat = exif.tobytes()
    img.save(image_path, exif=exif_dat)
```
In doing so, you cannot import the unicode json embedded the way pnginfo reads the webp. pnginfo.js also will be modified.
why parsing in text mode a json that's already clean? also what is the purpose of `let txt_chunks = {}`? do we expect more json chunks? like multiple exif tags? one for workflow and one for prompt? 
no one will ever do that. we custom node dev do not have your specs to embedd the json as you want in webp/jpeg/avif. 
We save the whole metadata in a single exif tag called UserComment, as everyone else.
Therefore, txt_chunks is unique, and contains a parsed json ready for use by app.js!
@audioscavenger
Copy link
Author

audioscavenger commented May 8, 2024

hold on... needs more tender care to validate the json parsing (removing [NaN] and those invalid entries)
also it still cannot work with tag injection from exiftool, when one convert from png to webp. With exiftool, we get type 5 tags instead of type 2
more research needed

@audioscavenger
Copy link
Author

audioscavenger commented May 23, 2024

updated pnginfo.js by removing invalid data that sometimes get saved (NaN instead of an integer)
Other than that, I use webp as my daily driver with this patch and hope you will consider it! or explain how we should save the webp metadata to get it loaded with your current code :)
Still cannot load metadata from a webp converted from png with exiftool, but that's okay. No one uses this tool anyway.

@comfyanonymous
Copy link
Owner

I'm not sure what the point of this PR is since it breaks loading the workflow from WEBP files created with the SaveAnimatedWEBP node.

@audioscavenger
Copy link
Author

you fixed it! somehow, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants