mirror of
https://github.com/ciromattia/kcc
synced 2025-12-22 22:22:21 +00:00
Automatic matching of Panel View layout
This commit is contained in:
@@ -44,11 +44,18 @@ import pdfjpgextract
|
|||||||
def buildHTML(path, imgfile):
|
def buildHTML(path, imgfile):
|
||||||
filename = getImageFileName(imgfile)
|
filename = getImageFileName(imgfile)
|
||||||
if filename is not None:
|
if filename is not None:
|
||||||
# All files marked with this sufix need horizontal Panel View.
|
if "_kccrot" in str(filename):
|
||||||
if "_kccrotated" in str(filename):
|
rotatedPage = True
|
||||||
rotate = True
|
|
||||||
else:
|
else:
|
||||||
rotate = False
|
rotatedPage = False
|
||||||
|
if "_kccnh" in str(filename):
|
||||||
|
noHorizontalPV = True
|
||||||
|
else:
|
||||||
|
noHorizontalPV = False
|
||||||
|
if "_kccnv" in str(filename):
|
||||||
|
noVerticalPV = True
|
||||||
|
else:
|
||||||
|
noVerticalPV = False
|
||||||
htmlpath = ''
|
htmlpath = ''
|
||||||
postfix = ''
|
postfix = ''
|
||||||
backref = 1
|
backref = 1
|
||||||
@@ -79,7 +86,8 @@ def buildHTML(path, imgfile):
|
|||||||
imgfile, "\" class=\"singlePage\"/></div>\n"
|
imgfile, "\" class=\"singlePage\"/></div>\n"
|
||||||
])
|
])
|
||||||
if options.panelview:
|
if options.panelview:
|
||||||
if rotate:
|
if not noHorizontalPV and not noVerticalPV:
|
||||||
|
if rotatedPage:
|
||||||
if options.righttoleft:
|
if options.righttoleft:
|
||||||
order = [1, 3, 2, 4]
|
order = [1, 3, 2, 4]
|
||||||
else:
|
else:
|
||||||
@@ -89,29 +97,39 @@ def buildHTML(path, imgfile):
|
|||||||
order = [2, 1, 4, 3]
|
order = [2, 1, 4, 3]
|
||||||
else:
|
else:
|
||||||
order = [1, 2, 3, 4]
|
order = [1, 2, 3, 4]
|
||||||
f.writelines(["<div id=\"BoxTL\"><a class=\"app-amzn-magnify\" data-app-amzn-magnify=",
|
boxes = ["BoxTL", "BoxTR", "BoxBL", "BoxBR"]
|
||||||
"'{\"targetId\":\"BoxTL-Panel-Parent\", \"ordinal\":" + str(order[0]) + "}'></a></div>\n",
|
elif noHorizontalPV and not noVerticalPV:
|
||||||
"<div id=\"BoxTR\"><a class=\"app-amzn-magnify\" data-app-amzn-magnify=",
|
if rotatedPage:
|
||||||
"'{\"targetId\":\"BoxTR-Panel-Parent\", \"ordinal\":" + str(order[1]) + "}'></a></div>\n",
|
if options.righttoleft:
|
||||||
"<div id=\"BoxBL\"><a class=\"app-amzn-magnify\" data-app-amzn-magnify=",
|
order = [2, 1]
|
||||||
"'{\"targetId\":\"BoxBL-Panel-Parent\", \"ordinal\":" + str(order[2]) + "}'></a></div>\n",
|
else:
|
||||||
"<div id=\"BoxBR\"><a class=\"app-amzn-magnify\" data-app-amzn-magnify="
|
order = [1, 2]
|
||||||
"'{\"targetId\":\"BoxBR-Panel-Parent\", \"ordinal\":" + str(order[3]) + "}'></a></div>\n"
|
else:
|
||||||
])
|
order = [1, 2]
|
||||||
|
boxes = ["BoxT", "BoxB"]
|
||||||
|
elif not noHorizontalPV and noVerticalPV:
|
||||||
|
if rotatedPage:
|
||||||
|
order = [1, 2]
|
||||||
|
else:
|
||||||
|
if options.righttoleft:
|
||||||
|
order = [2, 1]
|
||||||
|
else:
|
||||||
|
order = [1, 2]
|
||||||
|
boxes = ["BoxL", "BoxR"]
|
||||||
|
else:
|
||||||
|
order = [1]
|
||||||
|
boxes = ["BoxC"]
|
||||||
|
for i in range(0, len(boxes)):
|
||||||
|
f.writelines(["<div id=\"" + boxes[i] + "\"><a class=\"app-amzn-magnify\" data-app-amzn-magnify=",
|
||||||
|
"'{\"targetId\":\"" + boxes[i] + "-Panel-Parent\", \"ordinal\":" + str(order[i]),
|
||||||
|
"}'></a></div>\n"])
|
||||||
if options.quality == 2:
|
if options.quality == 2:
|
||||||
imgfilepv = string.split(imgfile, ".")
|
imgfilepv = string.split(imgfile, ".")
|
||||||
imgfilepv[0] = imgfilepv[0].split("_kccx")[0]
|
imgfilepv[0] = imgfilepv[0].split("_kccx")[0].replace("_kccnh", "").replace("_kccnv", "")
|
||||||
imgfilepv[0] += "_kcchq"
|
imgfilepv[0] += "_kcchq"
|
||||||
imgfilepv = string.join(imgfilepv, ".")
|
imgfilepv = string.join(imgfilepv, ".")
|
||||||
else:
|
else:
|
||||||
imgfilepv = imgfile
|
imgfilepv = imgfile
|
||||||
if not "_kccx" in filename[0]:
|
|
||||||
for box in ["BoxTL", "BoxTR", "BoxBL", "BoxBR"]:
|
|
||||||
f.writelines(["<div id=\"" + box + "-Panel-Parent\" class=\"target-mag-parent\"><div id=\"" + box,
|
|
||||||
"-Panel\" class=\"target-mag\"><img src=\"", "../" * backref, "Images/", postfix,
|
|
||||||
imgfilepv, "\" alt=\"" + imgfilepv, "\"/></div></div>\n"
|
|
||||||
])
|
|
||||||
else:
|
|
||||||
xy = string.split(filename[0], "_kccx")[1]
|
xy = string.split(filename[0], "_kccx")[1]
|
||||||
x = string.split(xy, "_kccy")[0].lstrip("0")
|
x = string.split(xy, "_kccy")[0].lstrip("0")
|
||||||
y = string.split(xy, "_kccy")[1].lstrip("0")
|
y = string.split(xy, "_kccy")[1].lstrip("0")
|
||||||
@@ -123,20 +141,19 @@ def buildHTML(path, imgfile):
|
|||||||
y = "-" + str(float(y)/100) + "%"
|
y = "-" + str(float(y)/100) + "%"
|
||||||
else:
|
else:
|
||||||
y = "0%"
|
y = "0%"
|
||||||
f.writelines(["<div id=\"BoxTL-Panel-Parent\" class=\"target-mag-parent\"><div id=\"BoxTL",
|
boxStyles = {"BoxTL": "left:" + x + ";top:" + y + ";",
|
||||||
"-Panel\" class=\"target-mag\"><img style=\"left:" + x + ";top:" + y + ";\" src=\"",
|
"BoxTR": "right:" + x + ";top:" + y + ";",
|
||||||
"../" * backref, "Images/", postfix, imgfilepv, "\" alt=\"" + imgfilepv,
|
"BoxBL": "left:" + x + ";bottom:" + y + ";",
|
||||||
"\"/></div></div>\n",
|
"BoxBR": "right:" + x + ";bottom:" + y + ";",
|
||||||
"<div id=\"BoxTR-Panel-Parent\" class=\"target-mag-parent\"><div id=\"BoxTR",
|
"BoxT": "left:-25%;top:" + y + ";",
|
||||||
"-Panel\" class=\"target-mag\"><img style=\"right:" + x + ";top:" + y + ";\" src=\"",
|
"BoxB": "left:-25%;bottom:" + y + ";",
|
||||||
"../" * backref, "Images/", postfix, imgfilepv, "\" alt=\"" + imgfilepv,
|
"BoxL": "left:" + x + ";top:-25%;",
|
||||||
"\"/></div></div>\n",
|
"BoxR": "right:" + x + ";top:-25%;",
|
||||||
"<div id=\"BoxBL-Panel-Parent\" class=\"target-mag-parent\"><div id=\"BoxBL",
|
"BoxC": "right:-25%;top:-25%;"
|
||||||
"-Panel\" class=\"target-mag\"><img style=\"left:" + x + ";bottom:" + y + ";\" src=\"",
|
}
|
||||||
"../" * backref, "Images/", postfix, imgfilepv, "\" alt=\"" + imgfilepv,
|
for box in boxes:
|
||||||
"\"/></div></div>\n",
|
f.writelines(["<div id=\"" + box + "-Panel-Parent\" class=\"target-mag-parent\"><div id=\"",
|
||||||
"<div id=\"BoxBR-Panel-Parent\" class=\"target-mag-parent\"><div id=\"BoxBR",
|
"Generic-Panel\" class=\"target-mag\"><img style=\"" + boxStyles[box] + "\" src=\"",
|
||||||
"-Panel\" class=\"target-mag\"><img style=\"right:" + x + ";bottom:" + y + ";\" src=\"",
|
|
||||||
"../" * backref, "Images/", postfix, imgfilepv, "\" alt=\"" + imgfilepv,
|
"../" * backref, "Images/", postfix, imgfilepv, "\" alt=\"" + imgfilepv,
|
||||||
"\"/></div></div>\n",
|
"\"/></div></div>\n",
|
||||||
])
|
])
|
||||||
@@ -445,6 +462,36 @@ def genEpubStruct(path):
|
|||||||
"height: ", str(panelviewsize[1]), "px;\n",
|
"height: ", str(panelviewsize[1]), "px;\n",
|
||||||
"width: ", str(panelviewsize[0]), "px;\n",
|
"width: ", str(panelviewsize[0]), "px;\n",
|
||||||
"}\n",
|
"}\n",
|
||||||
|
"#Generic-Panel {\n",
|
||||||
|
"top: 0;\n",
|
||||||
|
"height: 100%;\n",
|
||||||
|
"width: 100%;\n",
|
||||||
|
"}\n",
|
||||||
|
"#BoxC {\n",
|
||||||
|
"top: 0;\n",
|
||||||
|
"height: 100%;\n",
|
||||||
|
"width: 100%;\n",
|
||||||
|
"}\n",
|
||||||
|
"#BoxT {\n",
|
||||||
|
"top: 0;\n",
|
||||||
|
"height: 50%;\n",
|
||||||
|
"width: 100%;\n",
|
||||||
|
"}\n",
|
||||||
|
"#BoxB {\n",
|
||||||
|
"bottom: 0;\n",
|
||||||
|
"height: 50%;\n",
|
||||||
|
"width: 100%;\n",
|
||||||
|
"}\n",
|
||||||
|
"#BoxL {\n",
|
||||||
|
"left: 0;\n",
|
||||||
|
"height: 100%;\n",
|
||||||
|
"width: 50%;\n",
|
||||||
|
"}\n",
|
||||||
|
"#BoxR {\n",
|
||||||
|
"right: 0;\n",
|
||||||
|
"height: 100%;\n",
|
||||||
|
"width: 50%;\n",
|
||||||
|
"}\n",
|
||||||
"#BoxTL {\n",
|
"#BoxTL {\n",
|
||||||
"top: 0;\n",
|
"top: 0;\n",
|
||||||
"left: 0;\n",
|
"left: 0;\n",
|
||||||
@@ -468,47 +515,7 @@ def genEpubStruct(path):
|
|||||||
"right: 0;\n",
|
"right: 0;\n",
|
||||||
"height: 50%;\n",
|
"height: 50%;\n",
|
||||||
"width: 50%;\n",
|
"width: 50%;\n",
|
||||||
"}\n",
|
"}",
|
||||||
"#BoxTL-Panel {\n",
|
|
||||||
"top: 0;\n",
|
|
||||||
"left: 0;\n",
|
|
||||||
"height: 100%;\n",
|
|
||||||
"width: 100%;\n",
|
|
||||||
"}\n",
|
|
||||||
"#BoxTL-Panel img {\n",
|
|
||||||
"top: 0%;\n",
|
|
||||||
"left: 0%;\n",
|
|
||||||
"}\n",
|
|
||||||
"#BoxTR-Panel {\n",
|
|
||||||
"top: 0;\n",
|
|
||||||
"right: 0;\n",
|
|
||||||
"height: 100%;\n",
|
|
||||||
"width: 100%;\n",
|
|
||||||
"}\n",
|
|
||||||
"#BoxTR-Panel img {\n",
|
|
||||||
"top: 0%;\n",
|
|
||||||
"right: 0%;\n",
|
|
||||||
"}\n",
|
|
||||||
"#BoxBL-Panel {\n",
|
|
||||||
"bottom: 0;\n",
|
|
||||||
"left: 0;\n",
|
|
||||||
"height: 100%;\n",
|
|
||||||
"width: 100%;\n",
|
|
||||||
"}\n",
|
|
||||||
"#BoxBL-Panel img {\n",
|
|
||||||
"bottom: 0%;\n",
|
|
||||||
"left: 0%;\n",
|
|
||||||
"}\n",
|
|
||||||
"#BoxBR-Panel {\n",
|
|
||||||
"bottom: 0;\n",
|
|
||||||
"right: 0;\n",
|
|
||||||
"height: 100%;\n",
|
|
||||||
"width: 100%;\n",
|
|
||||||
"}\n",
|
|
||||||
"#BoxBR-Panel img {\n",
|
|
||||||
"bottom: 0%;\n",
|
|
||||||
"right: 0%;\n",
|
|
||||||
"}"
|
|
||||||
])
|
])
|
||||||
f.close()
|
f.close()
|
||||||
for (dirpath, dirnames, filenames) in os.walk(os.path.join(path, 'OEBPS', 'Images')):
|
for (dirpath, dirnames, filenames) in os.walk(os.path.join(path, 'OEBPS', 'Images')):
|
||||||
|
|||||||
36
kcc/image.py
36
kcc/image.py
@@ -152,13 +152,17 @@ class ComicPage:
|
|||||||
if not color:
|
if not color:
|
||||||
self.image = self.image.convert('L') # convert to grayscale
|
self.image = self.image.convert('L') # convert to grayscale
|
||||||
if suffix == "R":
|
if suffix == "R":
|
||||||
suffix = "_kccrotated"
|
suffix = "_kccrot"
|
||||||
else:
|
else:
|
||||||
suffix = ""
|
suffix = ""
|
||||||
if wipe:
|
if wipe:
|
||||||
os.remove(os.path.join(targetdir, self.filename))
|
os.remove(os.path.join(targetdir, self.filename))
|
||||||
else:
|
else:
|
||||||
suffix += "_kcchq"
|
suffix += "_kcchq"
|
||||||
|
if self.noHPV:
|
||||||
|
suffix += "_kccnh"
|
||||||
|
if self.noVPV:
|
||||||
|
suffix += "_kccnv"
|
||||||
if self.border:
|
if self.border:
|
||||||
suffix += "_kccx" + str(self.border[0]) + "_kccy" + str(self.border[1])
|
suffix += "_kccx" + str(self.border[0]) + "_kccy" + str(self.border[1])
|
||||||
if forcepng:
|
if forcepng:
|
||||||
@@ -207,10 +211,20 @@ class ComicPage:
|
|||||||
borderh = (self.size[1] - self.image.size[1]) / 2
|
borderh = (self.size[1] - self.image.size[1]) / 2
|
||||||
self.image = ImageOps.expand(self.image, border=(borderw, borderh), fill=fill)
|
self.image = ImageOps.expand(self.image, border=(borderw, borderh), fill=fill)
|
||||||
if generateBorder:
|
if generateBorder:
|
||||||
|
if (self.image.size[0]-(2*borderw))*1.5 < self.size[0]:
|
||||||
|
self.noHPV = True
|
||||||
|
else:
|
||||||
|
self.noHPV = None
|
||||||
|
if (self.image.size[1]-(2*borderh))*1.5 < self.size[1]:
|
||||||
|
self.noVPV = True
|
||||||
|
else:
|
||||||
|
self.noVPV = None
|
||||||
self.border = [int(round(float(borderw)/float(self.image.size[0])*100, 2)*100*1.5),
|
self.border = [int(round(float(borderw)/float(self.image.size[0])*100, 2)*100*1.5),
|
||||||
int(round(float(borderh)/float(self.image.size[1])*100, 2)*100*1.5)]
|
int(round(float(borderh)/float(self.image.size[1])*100, 2)*100*1.5)]
|
||||||
else:
|
else:
|
||||||
self.border = None
|
self.border = None
|
||||||
|
self.noHPV = None
|
||||||
|
self.noVPV = None
|
||||||
return self.image
|
return self.image
|
||||||
else:
|
else:
|
||||||
method = Image.BILINEAR
|
method = Image.BILINEAR
|
||||||
@@ -221,10 +235,20 @@ class ComicPage:
|
|||||||
border = ImageOps.invert(self.image).getbbox()
|
border = ImageOps.invert(self.image).getbbox()
|
||||||
else:
|
else:
|
||||||
border = self.image.getbbox()
|
border = self.image.getbbox()
|
||||||
|
if (border[2]-border[0])*1.5 < self.size[0]:
|
||||||
|
self.noHPV = True
|
||||||
|
else:
|
||||||
|
self.noHPV = None
|
||||||
|
if (border[3]-border[1])*1.5 < self.size[1]:
|
||||||
|
self.noVPV = True
|
||||||
|
else:
|
||||||
|
self.noVPV = None
|
||||||
self.border = [int(round(float(border[0])/float(self.image.size[0])*100, 2)*100*1.5),
|
self.border = [int(round(float(border[0])/float(self.image.size[0])*100, 2)*100*1.5),
|
||||||
int(round(float(border[1])/float(self.image.size[1])*100, 2)*100*1.5)]
|
int(round(float(border[1])/float(self.image.size[1])*100, 2)*100*1.5)]
|
||||||
else:
|
else:
|
||||||
self.border = None
|
self.border = None
|
||||||
|
self.noHPV = None
|
||||||
|
self.noVPV = None
|
||||||
return self.image
|
return self.image
|
||||||
ratioDev = float(self.size[0]) / float(self.size[1])
|
ratioDev = float(self.size[0]) / float(self.size[1])
|
||||||
if (float(self.image.size[0]) / float(self.image.size[1])) < ratioDev:
|
if (float(self.image.size[0]) / float(self.image.size[1])) < ratioDev:
|
||||||
@@ -239,10 +263,20 @@ class ComicPage:
|
|||||||
border = ImageOps.invert(self.image).getbbox()
|
border = ImageOps.invert(self.image).getbbox()
|
||||||
else:
|
else:
|
||||||
border = self.image.getbbox()
|
border = self.image.getbbox()
|
||||||
|
if (border[2]-border[0])*1.5 < self.size[0]:
|
||||||
|
self.noHPV = True
|
||||||
|
else:
|
||||||
|
self.noHPV = None
|
||||||
|
if (border[3]-border[1])*1.5 < self.size[1]:
|
||||||
|
self.noVPV = True
|
||||||
|
else:
|
||||||
|
self.noVPV = None
|
||||||
self.border = [int(round(float(border[0])/float(self.image.size[0])*100, 2)*100*1.5),
|
self.border = [int(round(float(border[0])/float(self.image.size[0])*100, 2)*100*1.5),
|
||||||
int(round(float(border[1])/float(self.image.size[1])*100, 2)*100*1.5)]
|
int(round(float(border[1])/float(self.image.size[1])*100, 2)*100*1.5)]
|
||||||
else:
|
else:
|
||||||
self.border = None
|
self.border = None
|
||||||
|
self.noHPV = None
|
||||||
|
self.noVPV = None
|
||||||
return self.image
|
return self.image
|
||||||
|
|
||||||
def splitPage(self, targetdir, righttoleft=False, rotate=False):
|
def splitPage(self, targetdir, righttoleft=False, rotate=False):
|
||||||
|
|||||||
Reference in New Issue
Block a user