View Single Post
Old 04-22-2019, 03:03 PM   #5
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,739
Karma: 24031403
Join Date: Dec 2010
Device: Kindle PW2
@nirosan

Copy a .png file to your plugin folder, rename it to cover.png and test the following code:

Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, os, string, random

def run(bk):
    image_name = 'cover.png'
    mime_type = 'image/png'
    image_path = os.path.join(bk._w.plugin_dir, bk._w.plugin_name, image_name)
    
    if os.path.isfile(image_path):
        with open(image_path, 'rb') as f:
            image_data = f.read()
    
        try:
            bk.addfile(image_name, image_name, image_data, mime_type)
        except:
            random_prefix = ''.join(random.choices(string.ascii_uppercase + string.digits, k=6))
            image_name = random_prefix + image_name
            bk.addfile(image_name, image_name, image_data, mime_type)
            
    return 0
It should add a cover.png file to your epub.
Doitsu is offline   Reply With Quote