How to load a texture from a file handle

From my Panda3D app, I am calling an external application, webkit2png.py to render an HTML page to a PNG file, which I then pipe to my Panda3D application from that applications stdout.

The PNG file generated is not saved to disk, it is simply piped to me via the stdout of the webkit2png app.

Here is a snippet of some of this code:

pobj = Popen(["python", "webkit2png.py", "http://www.panda3d.org/"], stdin=PIPE, stdout=PIPE)

fin, fout = pobj.stdin, pobj.stdout

pobj.wait()

At this point, fout is the file handle to stdout from webkit2png.py, and if you do a fout.read() you get the png image data.

What I am trying to figure out, is how to send this image data, or maybe the fout file handle to create a new Texture, without having to save the PNG to disk first.

At the moment, I can get it working fine if I save the PNG to disk first, but I would really like to avoid doing this if possible and just send the fout file handle or png data to the texture, but I can’t figure out how to do that.

There’s an example of doing exactly this in the manual: Loading resources from nonstandard sources

David