Replies: 1 comment
-
If anyone else finds this useful, I believe I have reliable output without having to install any extra external libraries for Pillow by doing some file manipulation directly to add the parameters to the PNG. I'm not sure I caught every possible edge case or problem, but it does work with UTF-8 characters and some other things I could think of for testing. I guess I can try it out for a while to see if I encounter any problems. I'm fine if the code gets used by whoever or incorporated. I'd also be happy to do a PR, but not sure what things (tests? or ??) I'd need to include to do that. It should save the information into the PNG files you get when you right click or click the "..." and save a generated image. Helpful for figuring out what you did later if all you can locate is the PNG file and not the original kra file later.
|
Beta Was this translation helpful? Give feedback.
-
I find that I save images from the generated results quite often and then when I go back to see how I created the images, they're just PNG files without information about the prompt or anything else.
So . . . I modified the code in my own installation to save the png generation metadata into the png. It's a bit of a workaround since whatever image format is normally used, I don't think really allows saving metadata without using Pillow (PIL) or some other library. I had trouble doing it all in memory and getting the internal format into the pillow format of bytes, so my hacky workaround is to save to a temp file and then use pillow to open the temp file and re-save to the final name with pillow and metadata instead.
If there is general interest, I might be able to make something less hacky or someone who knows more than me could modify to be better. One issue is that Pillow uses binaries, so it's sort of a PITA to include in any zip plugin which I guess would require the binaries to be included for common architectures (Windows x64, Linux x64/arm, MacOS x64/arm for Python 3.10.x) or maybe there is a better way since I don't know all the details of packaging for krita. Or maybe there is a way to manually get into PNG rewriting to include that metadata using binary manipulations of a file directly (which would not require including all those Pillow libraries).
Anyway, I copied the PIL directory from a Python 3.10 install into the plugin directory locally and made these code changes and it works for anyone who wants similar functionality.
My hacky code changes to model.py:
:-)
Beta Was this translation helpful? Give feedback.
All reactions