I know I can save an RGB array to a file using
from matplotlib.pyplot import imsave
rgb = numpy.zeros([height,width,3], dtype=numpy.uint8)
paint_picture(rgb)
imsave("/tmp/whatever.png", rgb)
but now I want to write the PNG to a byte buffer instead of a file so I can later transmit those PNG bytes via HTTP. There must be no temporary files involved.
Bonus points if the answer has variations that support formats other than PNG.