There are several examples of loading an image file into a numpy array, but I do not have an image in a file on the local file system. Instead, I have a string variable img
that contains the data that makes up an image. For example:
# Currently here:
with open("imageFile.png") as f:
img = f.read()
# Would like to accomplish this:
npArray = loadStringToArray(img)
Writing this file back to the disk and calling one of the more common load functions seems impractical, so how do I "load" this image-as-a-string into a numpy array?
A bit of background - in my application, this image-as-a-string is delivered from a client via python sockets. The image isn't on the local machine; the example above is just that - an example. While writing the file to the local file system and then reading it back in is possible, I'd like to avoid doing that if I can.