PNG data without saving to file? - Printable Version +- Gimp-Forum.net (https://www.gimp-forum.net) +-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP) +--- Forum: General questions (https://www.gimp-forum.net/Forum-General-questions) +--- Thread: PNG data without saving to file? (/Thread-PNG-data-without-saving-to-file) |
PNG data without saving to file? - nchen - 09-09-2024 Hello, Is there a way to convert a layer to PNG data, and convert PNG data to a layer, without exporting to a file? I am trying to send a layer to a local server that accepts base64 encoded PNG data, receive base64 encoded PNG data, then convert that data back into a layer. My current process is as follows: > Save layer as PNG (pdb.gimp_file_save) > Read the PNG file data > Convert PNG data to base64 data > Send base64 data using websocket > Receive base64 data > Write the received data to the previously saved PNG file > Load the PNG file as layer (pdb.gimp_file_load_layer) > Delete PNG file The closest solution that I have found is to use PIL/Pillow. I have tried installing PIL6.2.2 and earlier versions with GIMP's python but receive the error: "The headers or library files could not be found for zlib, a required dependency when compiling Pillow from source." If there is a solution within GIMP, or someone might be able to help me get Pillow to work, I would greatly appreciate it! I am on Windows 10, using GIMP 2.10.38, and GIMP's Python 2.7.18. Please let me know if there is additional information I should provide. Thank you for your time! RE: PNG data without saving to file? - nchen - 09-10-2024 For context: I'm working on making a plugin that communicates with ComfyUI. Getting an answer for this would be great, as it would be compatible with existing nodes. I realize, however, that I can just create a new node that accepts GIMP layer data, which I have just done. RE: PNG data without saving to file? - Ofnuts - 09-10-2024 No, unless you want to rewrite your own plugin. Using a temporary disk file is not as bad as it looks, because with PNG the encoding is very slow (so you aren't adding that much time with the file I/O in a decent OS). If you can transfer the raw data (or something close such as BMP or Targa) you can get the layer as a python array using pixel regions. RE: PNG data without saving to file? - nchen - 09-10-2024 (09-10-2024, 12:19 AM)Ofnuts Wrote: No, unless you want to rewrite your own plugin. It looks like pixel regions is the best answer. The one issue I find with a temporary file is that it bloats the PF_IMAGE option selection with all of the deleted images. By the way, your high quality documentation throughout time has been instrumental in my development. Thank you so much! |