diff --git a/kindlecomicconverter/comic2ebook.py b/kindlecomicconverter/comic2ebook.py
index 1689d8d..ffff62f 100755
--- a/kindlecomicconverter/comic2ebook.py
+++ b/kindlecomicconverter/comic2ebook.py
@@ -88,7 +88,7 @@ def buildHTML(path, imgfile, imgfilepath):
if "BlackBackground" in options.imgMetadata[imgfilepath]:
additionalStyle = 'background-color:#000000;'
else:
- additionalStyle = 'background-color:#FFFFFF;'
+ additionalStyle = ''
postfix = ''
backref = 1
head = path
@@ -287,20 +287,27 @@ def buildOPF(dstdir, title, filelist, cover=None):
for author in options.authors:
f.writelines(["", author, "\n"])
f.writelines(["" + strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()) + "\n",
- "\n",
- "portrait\n",
- "portrait\n",
- "pre-paginated\n"])
+ "\n"])
if options.iskindle and options.profile != 'Custom':
- f.writelines(["\n",
+ "\n",
"\n",
- "\n",
"\n",
"\n",
"\n",
- "\n",
+ "\n",
"\n"])
+ if options.kfx:
+ f.writelines(["\n",
+ "\n"])
+ else:
+ f.writelines(["\n",
+ "\n"])
+ else:
+ f.writelines(["portrait\n",
+ "portrait\n",
+ "pre-paginated\n"])
f.writelines(["\n\n \n",
"- \n")
if options.righttoleft:
f.write("
\n\n")
+ pageside = "right"
else:
f.write("\n\n")
- for entry in reflist:
- f.write("\n")
+ pageside = "left"
+ if options.iskindle:
+ for entry in reflist:
+ if options.righttoleft:
+ if entry.endswith("-b"):
+ f.write("\n")
+ pageside = "right"
+ elif entry.endswith("-c"):
+ f.write("\n")
+ pageside = "right"
+ else:
+ f.write("\n")
+ if pageside == "right":
+ pageside = "left"
+ else:
+ pageside = "right"
+ else:
+ if entry.endswith("-b"):
+ f.write("\n")
+ pageside = "left"
+ elif entry.endswith("-c"):
+ f.write("\n")
+ pageside = "left"
+ else:
+ f.write("\n")
+ if pageside == "right":
+ pageside = "left"
+ else:
+ pageside = "right"
+ else:
+ for entry in reflist:
+ f.write("\n")
f.write("\n\n")
f.close()
os.mkdir(os.path.join(dstdir, 'META-INF'))
@@ -361,71 +401,72 @@ def buildEPUB(path, chapternames, tomenumber):
"display: block;\n",
"margin: 0;\n",
"padding: 0;\n",
- "}\n",
- "#PV {\n",
- "position: absolute;\n",
- "width: 100%;\n",
- "height: 100%;\n",
- "top: 0;\n",
- "left: 0;\n",
- "}\n",
- "#PV-T {\n",
- "top: 0;\n",
- "width: 100%;\n",
- "height: 50%;\n",
- "}\n",
- "#PV-B {\n",
- "bottom: 0;\n",
- "width: 100%;\n",
- "height: 50%;\n",
- "}\n",
- "#PV-L {\n",
- "left: 0;\n",
- "width: 49.5%;\n",
- "height: 100%;\n",
- "float: left;\n",
- "}\n",
- "#PV-R {\n",
- "right: 0;\n",
- "width: 49.5%;\n",
- "height: 100%;\n",
- "float: right;\n",
- "}\n",
- "#PV-TL {\n",
- "top: 0;\n",
- "left: 0;\n",
- "width: 49.5%;\n",
- "height: 50%;\n",
- "float: left;\n",
- "}\n",
- "#PV-TR {\n",
- "top: 0;\n",
- "right: 0;\n",
- "width: 49.5%;\n",
- "height: 50%;\n",
- "float: right;\n",
- "}\n",
- "#PV-BL {\n",
- "bottom: 0;\n",
- "left: 0;\n",
- "width: 49.5%;\n",
- "height: 50%;\n",
- "float: left;\n",
- "}\n",
- "#PV-BR {\n",
- "bottom: 0;\n",
- "right: 0;\n",
- "width: 49.5%;\n",
- "height: 50%;\n",
- "float: right;\n",
- "}\n",
- ".PV-P {\n",
- "width: 100%;\n",
- "height: 100%;\n",
- "top: 0;\n",
- "position: absolute;\n",
- "display: none;\n",
"}\n"])
+ if options.iskindle and options.panelview:
+ f.writelines(["#PV {\n",
+ "position: absolute;\n",
+ "width: 100%;\n",
+ "height: 100%;\n",
+ "top: 0;\n",
+ "left: 0;\n",
+ "}\n",
+ "#PV-T {\n",
+ "top: 0;\n",
+ "width: 100%;\n",
+ "height: 50%;\n",
+ "}\n",
+ "#PV-B {\n",
+ "bottom: 0;\n",
+ "width: 100%;\n",
+ "height: 50%;\n",
+ "}\n",
+ "#PV-L {\n",
+ "left: 0;\n",
+ "width: 49.5%;\n",
+ "height: 100%;\n",
+ "float: left;\n",
+ "}\n",
+ "#PV-R {\n",
+ "right: 0;\n",
+ "width: 49.5%;\n",
+ "height: 100%;\n",
+ "float: right;\n",
+ "}\n",
+ "#PV-TL {\n",
+ "top: 0;\n",
+ "left: 0;\n",
+ "width: 49.5%;\n",
+ "height: 50%;\n",
+ "float: left;\n",
+ "}\n",
+ "#PV-TR {\n",
+ "top: 0;\n",
+ "right: 0;\n",
+ "width: 49.5%;\n",
+ "height: 50%;\n",
+ "float: right;\n",
+ "}\n",
+ "#PV-BL {\n",
+ "bottom: 0;\n",
+ "left: 0;\n",
+ "width: 49.5%;\n",
+ "height: 50%;\n",
+ "float: left;\n",
+ "}\n",
+ "#PV-BR {\n",
+ "bottom: 0;\n",
+ "right: 0;\n",
+ "width: 49.5%;\n",
+ "height: 50%;\n",
+ "float: right;\n",
+ "}\n",
+ ".PV-P {\n",
+ "width: 100%;\n",
+ "height: 100%;\n",
+ "top: 0;\n",
+ "position: absolute;\n",
+ "display: none;\n",
+ "}\n"])
f.close()
for dirpath, dirnames, filenames in os.walk(os.path.join(path, 'OEBPS', 'Images')):
chapter = False
@@ -906,7 +947,7 @@ def makeParser():
outputOptions.add_option("-t", "--title", action="store", dest="title", default="defaulttitle",
help="Comic title [Default=filename or directory name]")
outputOptions.add_option("-f", "--format", action="store", dest="format", default="Auto",
- help="Output format (Available options: Auto, MOBI, EPUB, CBZ) [Default=Auto]")
+ help="Output format (Available options: Auto, MOBI, EPUB, CBZ, KFX) [Default=Auto]")
outputOptions.add_option("-b", "--batchsplit", type="int", dest="batchsplit", default="0",
help="Split output into multiple files. 0: Don't split 1: Automatic mode "
"2: Consider every subdirectory as separate volume [Default=0]")
@@ -953,6 +994,7 @@ def checkOptions():
options.panelview = True
options.iskindle = False
options.bordersColor = None
+ options.kfx = False
if options.format == 'Auto':
if options.profile in ['K1', 'K2', 'K34', 'K578', 'KPW', 'KV', 'KO']:
options.format = 'MOBI'
@@ -967,7 +1009,7 @@ def checkOptions():
if options.black_borders:
options.bordersColor = 'black'
# Splitting MOBI is not optional
- if options.format == 'MOBI' and options.batchsplit != 2:
+ if (options.format == 'MOBI' or options.format == 'KFX') and options.batchsplit != 2:
options.batchsplit = 1
# Older Kindle models don't support Panel View.
if options.profile == 'K1' or options.profile == 'K2' or options.profile == 'K34' or options.profile == 'KDX':
@@ -989,6 +1031,11 @@ def checkOptions():
# CBZ files on Kindle DX/DXG support higher resolution
if options.profile == 'KDX' and options.format == 'CBZ':
options.customheight = 1200
+ # KFX output create EPUB that might be can be by jhowell KFX Output Calibre plugin
+ if options.format == 'KFX':
+ options.format = 'EPUB'
+ options.kfx = True
+ options.panelview = False
# Override profile data
if options.customwidth != 0 or options.customheight != 0:
X = image.ProfileData.Profiles[options.profile][1][0]
diff --git a/kindlecomicconverter/image.py b/kindlecomicconverter/image.py
index fdb2ed4..21a486f 100755
--- a/kindlecomicconverter/image.py
+++ b/kindlecomicconverter/image.py
@@ -273,17 +273,17 @@ class ComicPage:
method = Image.BICUBIC
else:
method = Image.LANCZOS
- if self.opt.stretch:
+ if self.opt.stretch or (self.opt.kfx and ('-KCC-B' in self.targetPath or '-KCC-C' in self.targetPath)):
self.image = self.image.resize(self.size, method)
elif self.image.size[0] <= self.size[0] and self.image.size[1] <= self.size[1] and not self.opt.upscale:
- if self.opt.format == 'CBZ':
+ if self.opt.format == 'CBZ' or self.opt.kfx:
borderw = int((self.size[0] - self.image.size[0]) / 2)
borderh = int((self.size[1] - self.image.size[1]) / 2)
self.image = ImageOps.expand(self.image, border=(borderw, borderh), fill=self.fill)
if self.image.size[0] != self.size[0] or self.image.size[1] != self.size[1]:
self.image = ImageOps.fit(self.image, self.size, method=Image.BICUBIC, centering=(0.5, 0.5))
else:
- if self.opt.format == 'CBZ':
+ if self.opt.format == 'CBZ' or self.opt.kfx:
ratioDev = float(self.size[0]) / float(self.size[1])
if (float(self.image.size[0]) / float(self.image.size[1])) < ratioDev:
diff = int(self.image.size[1] * ratioDev) - self.image.size[0]