At it's simplest:
Code:
f=open(image_path, 'rb')
img=f.read()
f.close()
bk.addfile("MathmMlid", "MathMLImage.png", img, "image/png")
I've no idea if you need to use
self.bk.addfile. That all depends on whether you've passed the bk object as an argument to another object/class or not.
But your second parameter to addfile() needs to be a file name (with a valid extension).
Your first attempt is closer. Forget the encoding--just read in the data as binary. Figure out if you really need self.bk (or just bk) and make sure your basename parameter has a png extension.
Your second attempt tried to use a filepath parameter instead of binary image data.
Code:
addfile(uniqueid, basename, data, mime=None, properties=None, fallback=None, overlay=None):
The
Plugin to insert and wrap an image with SVG has a working example of adding an image to an epub via bk.addfile()