An old question, but I discovered something about this.
If you load an image using Pillow(PIL) and use base64.b64encode(img.tobytes()), then the Base64 code is invalid.
To get this to work, once your bytes are loaded into an Image class, Create a BytesIO object and then use this to save the image with the format to the BytesIO, i.e img.save(bt_ob, format="png").
Set seak to 0 and then use the output of the BytesIO object to create the Base64 encoded text
base64.b64encode(bt_ob.read()).decode()
This code will now work in the html in the "data:image/png;base64,<>" format.
Thus the html will only work on encoded data from a file like object, and a Pillow Image object doesn't produce that and so doesn't work
LzlqLzRBQ...
. After correcting the mistake, it looked more like/9j/4AAQSk...
and solved the issue. – Dysphonia