View Single Post
Old 04-22-2019, 01:20 PM   #2
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,664
Karma: 205039118
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
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()

Last edited by DiapDealer; 04-22-2019 at 01:38 PM.
DiapDealer is offline   Reply With Quote