I have a numpy array that I want to display through the src attribute of an img html component, kinda like this exemple :
def get_placeholder_thumbnail_html_value():
encoded_image = base64.b64encode(open("../assets/placeholder_thumbnail.png", 'rb').read())
return 'data:image/png;base64,{}'.format(encoded_image.decode())
The returned string can then be sent to be assigned to the src attribute of the corresponding img html component (I do it with a plotly dash callback).
Question : In the example above I do it from a png image on the server. How could I do the same from a numpy ndarray ?
def get_thumbnail_html_value_from_ndarray(ndarray):
return 'data:image/png;base64,{}'.format(<what here ?>)
It could be parsed to jpg or anything else, as long as the html can interpret the image properly.
EDIT : I could save it on the server as a png file then load it back with the example above, but it seems very inefficient, so I don't like this workaround.