Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Python] In-memory save png
#1
Hello,

I don't know, whether such a feature is realizable without certain changes to the Gio, but let me just describe my intent:

In a plugin, I want to send an "copy" of current image to a service using urllib.request.Request. Currently, I save the png image as usual using Gimp.file_save(), reopen it to read the data as bytes and attach them to a boundarized body. Then I send this body using the content-type 'multipart/form-data; boundary=xxxx' to the web service. I get an answer, evaluate the response and add the retrieved image to a new created layer. This all is working well and stable.

But I just want to get rid of storing the image into a file and read it again to a byte buffer. Already tried Gio.File.new_for_uri() and point the uri to memory, but my current knowledge for this aspect of the Gio library is literally not existent  Big Grin

Maybe there is a more elegant way to implement a in-memory file storage, as the export to PNG format is crucial.

Does someone has an approach in mind and could give me some pointers to study?

Thanks
Reply
#2
Probably unnecessary optimization. Your file is still cached in the RAM buffers so it won't be reread from disk.

Otherwise I would see if perhaps GEGL can do a PNG encoding to a ram buffer.

Kudos for using urlllib. I thought us humans were better off using requests?
Reply


Forum Jump: