-
-
Notifications
You must be signed in to change notification settings - Fork 509
Add generation metadata to saved pngs from the generated thumbnails (from right-click or ... menu on thumbnails) #1942
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
Conversation
…Pillow which are difficult to fulfil for all platforms
|
We can include it. There's a few changes I'd like to see:
|
|
Thanks for the good feedback. I'll see what I can do. It may take me a little time because of some other things going on, but it's very helpful. |
|
Ok. I did a round of refactoring. Have the PNG being saved from memory rather than writing to the file system and added the setting to save the metadata under the "interface" options, added translations and moved tests around and made sure they pass as well as linting with ruff, etc. It all seems to work fine to me. Give it a try and see what you think. I decided not to make full PNG writing code from scratch since there is already code to create PNGs that handles any extra complications about different color formats, compression, etc, and figured it was easier to leave it alone to just add the headers needed for the metadata. |
Acly
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good, I have a few smaller suggestions, then this should be ready
|
This is not something you need to worry about. The default is off but can be changed to suit a user's preferences. There are both reasons to want and reasons not to want to export this, which I understand. Personally, I may create other variations and different prompts that may not be saved within the KRZ file and it's useful for me to be able to track the generations I export. Other people enjoy sharing some of their process or have other reasons to want or not want this. I also have additional workflows (scaling/image enhancement) where this information is not passed along. Be aware this ONLY applies to saving a generated png directly from the generation thumbnails and not exporting through the Krita File > Export menu which is maybe what you're doing if you're spending weeks. It also follows the preference (off is default) as mentioned above which does not change the current behavior unless changed by the user. |
|
I believe this is ready since I made those changes, fixed a test and everything is still working afaict. Thanks. This will be nice to have the option without having to maintain my own branch or other things. |
|
i certainly don't want my meta in my images, I'll spend a week on some prompt tuning etc and the output image is a passion of time and love, iv had works from other output taken and passed of as there own. that's the worst feeling in the world. if implemented the default should be off, for myself i save the .krz for work flows and data information. |
thanks, where does right clicking the generated thumb and saving it go to, i saved but can't find it to test it, iv been away for a year lot of new stuff |
|
When saving generated images from the thumbnails they are saved in the same directory where the original file is saved. I believe the option is grayed out if the file is not saved anywhere (such as a new image not saved yet). |
|
Thanks, works fine for me One thing I noticed is that it starts metadata with "Prompt: ", whereas A1111 starts with the actual prompt directly (at least some 1+year old images I had lying around do). It doesn't particularly matter to me, but maybe it won't be read correctly in some viewers. |
|
Thank you for catching that. I could do a tiny PR to change that or you're welcome to change it if you'd rather. Thanks for your help! |
|
changed it: 11cd888 |
|
Was it expected that this would not include the style influence on the metadata saved to the PNG? Seems like all that is missing, meaning the workflow opened in ComfyUI using the image cannot reproduce Krita AI Diffusion images. |
I hope this is helpful and I know at least a few other people are interested, but feel free to tell me to get lost if it's not something you can deal with and I'll just keep updating it for myself after every new release.
I find it useful to save the images from the generation thumbnails (select thumbnails and right-click or click "..." and save image). Since I may come back to the PNGs later, it's very helpful to have some generation metadata in there (and currently none that I could see for files saved this way).
I've been running some code locally for about 4 months and haven't had any failures with thousands of images saved (also tested some UTF-8 characters like 4-bytle emoji and other characters in the metadata and it all seems to work).
I was originally going to use Pillow to do this, but there is a whole nightmare waiting with Pillow since it requires per-platform binaries and makes things heavier, so found out that writing the headers into existing PNG files is relatively straight-forward so could just include a method to do it without all the overhead.
I added most of the code to the util class, but don't know if it belongs there or elsewhere (though they are metadata/file rewriting utils).
Trying to catch a plethora of exceptions so if something goes wrong it just saves the file and doesn't save the metadata and also tried to make minimal changes to existing code.
I looked into contributing guidelines, added some tests, ruff passes.
I think I had some trouble running tests which may require additional server setup or something, sorry I'm a bit lost about how to do that.
So I don't know if this interferes with any of the other tests but the util tests pass, since I'm not sure I have a complete testing setup.
LMK what you think and I'm happy to try to make additional changes if this is something you're interested in including. I think it makes the PNGs a lot nicer so you have some idea how they were generated.