![]() |
Is it possible to add image file via plugin?
Hi,
I am trying to write a plugin which generate math formulas as image. Is it possible to add the generated image file to ebook? If yes how can I do this? What I have tried: Quote:
Quote:
I have already checked the image file exists. Thank you |
At it's simplest:
Code:
f=open(image_path, 'rb')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): |
Thank you for quick reply.
I changed it to: Quote:
Quote:
Thank you |
Yeah, trying to debug-print binary image data to the Plugin Runner window probably isn't a very good idea.
Get rid of: Code:
print("Img: ", img) |
@nirosan
Copy a .png file to your plugin folder, rename it to cover.png and test the following code: Code:
#!/usr/bin/env python |
Quote:
|
Thank you very much
yeah itīs works |
You've used PNG images.
If the epub is going to be used to generate a Kindle file, Kindlegen will convert it to either GIF or JPEG as its fancy takes. So better to choose one of those formats yourself which will pass through, rather than PNG and risk it becoming a larger and blurrier JPEG. I'd use GIF for this. Also, whether you use GIF or PNG, for an image of text, I restrict to monochrome and I reduce the palette to 4 colours, very compact, but still avoids jaggies. 8 or 16 colours is slightly smoother but more does not improve quality. For extra credit, inspect the palette and make the darkest grey 100% black; I can do this in Irfanview manually, but maybe your images come like that to begin with. |
| All times are GMT -4. The time now is 08:29 PM. |
Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.