mirror of
https://github.com/ciromattia/kcc
synced 2026-06-07 07:03:26 +00:00
Overhauled Panel View support
This commit is contained in:
+45
-31
@@ -129,34 +129,47 @@ def buildHTML(path, imgfile):
|
|||||||
"}'></a></div>\n"])
|
"}'></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].replace("_kccnh", "").replace("_kccnv", "")
|
imgfilepv[0] = imgfilepv[0].split("_kccxl")[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 "_kccx" in filename[0]:
|
if "_kccxl" in filename[0]:
|
||||||
xy = string.split(filename[0], "_kccx")[1]
|
borders = filename[0].split('_kccxl')[1]
|
||||||
x = string.split(xy, "_kccy")[0].lstrip("0")
|
borders = re.findall('[0-9]{1,6}', borders)
|
||||||
y = string.split(xy, "_kccy")[1].lstrip("0")
|
xl = borders[0].lstrip("0")
|
||||||
if x != "":
|
yu = borders[1].lstrip("0")
|
||||||
x = "-" + str(float(x)/100) + "%"
|
xr = borders[2].lstrip("0")
|
||||||
|
yd = borders[3].lstrip("0")
|
||||||
|
if xl != "":
|
||||||
|
xl = "-" + str(xl) + "px"
|
||||||
else:
|
else:
|
||||||
x = "0%"
|
xl = "0px"
|
||||||
if y != "":
|
if xr != "":
|
||||||
y = "-" + str(float(y)/100) + "%"
|
xr = "-" + str(xr) + "px"
|
||||||
else:
|
else:
|
||||||
y = "0%"
|
xr = "0px"
|
||||||
|
if yu != "":
|
||||||
|
yu = "-" + str(yu) + "px"
|
||||||
|
else:
|
||||||
|
yu = "0px"
|
||||||
|
if yd != "":
|
||||||
|
yd = "-" + str(yd) + "px"
|
||||||
|
else:
|
||||||
|
yd = "0px"
|
||||||
else:
|
else:
|
||||||
x = "0%"
|
xl = "0px"
|
||||||
y = "0%"
|
yu = "0px"
|
||||||
boxStyles = {"BoxTL": "left:" + x + ";top:" + y + ";",
|
xr = "0px"
|
||||||
"BoxTR": "right:" + x + ";top:" + y + ";",
|
yd = "0px"
|
||||||
"BoxBL": "left:" + x + ";bottom:" + y + ";",
|
boxStyles = {"BoxTL": "left:" + xl + ";top:" + yu + ";",
|
||||||
"BoxBR": "right:" + x + ";bottom:" + y + ";",
|
"BoxTR": "right:" + xr + ";top:" + yu + ";",
|
||||||
"BoxT": "left:-25%;top:" + y + ";",
|
"BoxBL": "left:" + xl + ";bottom:" + yd + ";",
|
||||||
"BoxB": "left:-25%;bottom:" + y + ";",
|
"BoxBR": "right:" + xr + ";bottom:" + yd + ";",
|
||||||
"BoxL": "left:" + x + ";top:-25%;",
|
"BoxT": "left:-25%;top:" + yu + ";",
|
||||||
"BoxR": "right:" + x + ";top:-25%;",
|
"BoxB": "left:-25%;bottom:" + yd + ";",
|
||||||
|
"BoxL": "left:" + xl + ";top:-25%;",
|
||||||
|
"BoxR": "right:" + xr + ";top:-25%;",
|
||||||
"BoxC": "right:-25%;top:-25%;"
|
"BoxC": "right:-25%;top:-25%;"
|
||||||
}
|
}
|
||||||
for box in boxes:
|
for box in boxes:
|
||||||
@@ -295,7 +308,7 @@ def getImageFileName(imgfile):
|
|||||||
return filename
|
return filename
|
||||||
|
|
||||||
|
|
||||||
def applyImgOptimization(img, opt, overrideQuality=5):
|
def applyImgOptimization(img, opt, hqImage=None):
|
||||||
if not img.fill:
|
if not img.fill:
|
||||||
img.getImageFill(opt.webtoon)
|
img.getImageFill(opt.webtoon)
|
||||||
if not opt.webtoon:
|
if not opt.webtoon:
|
||||||
@@ -303,8 +316,9 @@ def applyImgOptimization(img, opt, overrideQuality=5):
|
|||||||
if opt.cutpagenumbers and not opt.webtoon:
|
if opt.cutpagenumbers and not opt.webtoon:
|
||||||
img.cutPageNumber()
|
img.cutPageNumber()
|
||||||
img.optimizeImage(opt.gamma)
|
img.optimizeImage(opt.gamma)
|
||||||
if overrideQuality != 5:
|
if hqImage:
|
||||||
img.resizeImage(opt.upscale, opt.stretch, opt.bordersColor, overrideQuality)
|
img.resizeImage(opt.upscale, opt.stretch, opt.bordersColor, 0)
|
||||||
|
img.calculateBorder(hqImage)
|
||||||
else:
|
else:
|
||||||
img.resizeImage(opt.upscale, opt.stretch, opt.bordersColor, opt.quality)
|
img.resizeImage(opt.upscale, opt.stretch, opt.bordersColor, opt.quality)
|
||||||
if opt.forcepng and not opt.forcecolor:
|
if opt.forcepng and not opt.forcecolor:
|
||||||
@@ -378,12 +392,12 @@ def fileImgProcess(work):
|
|||||||
applyImgOptimization(img1, opt)
|
applyImgOptimization(img1, opt)
|
||||||
img1.saveToDir(dirpath, opt.forcepng, opt.forcecolor, wipe)
|
img1.saveToDir(dirpath, opt.forcepng, opt.forcecolor, wipe)
|
||||||
if opt.quality == 2:
|
if opt.quality == 2:
|
||||||
img3 = image.ComicPage(split[0], opt.profileData, img0.fill)
|
img0b = image.ComicPage(split[0], opt.profileData, img0.fill)
|
||||||
applyImgOptimization(img3, opt, 0)
|
applyImgOptimization(img0b, opt, img0)
|
||||||
img3.saveToDir(dirpath, opt.forcepng, opt.forcecolor, True)
|
img0b.saveToDir(dirpath, opt.forcepng, opt.forcecolor, True)
|
||||||
img4 = image.ComicPage(split[1], opt.profileData, img1.fill)
|
img1b = image.ComicPage(split[1], opt.profileData, img1.fill)
|
||||||
applyImgOptimization(img4, opt, 0)
|
applyImgOptimization(img1b, opt, img1)
|
||||||
img4.saveToDir(dirpath, opt.forcepng, opt.forcecolor, True)
|
img1b.saveToDir(dirpath, opt.forcepng, opt.forcecolor, True)
|
||||||
else:
|
else:
|
||||||
applyImgOptimization(img, opt)
|
applyImgOptimization(img, opt)
|
||||||
img.saveToDir(dirpath, opt.forcepng, opt.forcecolor, wipe)
|
img.saveToDir(dirpath, opt.forcepng, opt.forcecolor, wipe)
|
||||||
@@ -392,7 +406,7 @@ def fileImgProcess(work):
|
|||||||
if img.rotated:
|
if img.rotated:
|
||||||
img2.image = img2.image.rotate(90)
|
img2.image = img2.image.rotate(90)
|
||||||
img2.rotated = True
|
img2.rotated = True
|
||||||
applyImgOptimization(img2, opt, 0)
|
applyImgOptimization(img2, opt, img)
|
||||||
img2.saveToDir(dirpath, opt.forcepng, opt.forcecolor, True)
|
img2.saveToDir(dirpath, opt.forcepng, opt.forcecolor, True)
|
||||||
except StandardError:
|
except StandardError:
|
||||||
return str(sys.exc_info()[1])
|
return str(sys.exc_info()[1])
|
||||||
|
|||||||
+25
-50
@@ -201,7 +201,8 @@ class ComicPage:
|
|||||||
if self.noVPV:
|
if self.noVPV:
|
||||||
suffix += "_kccnv"
|
suffix += "_kccnv"
|
||||||
if self.border:
|
if self.border:
|
||||||
suffix += "_kccx" + str(self.border[0]) + "_kccy" + str(self.border[1])
|
suffix += "_kccxl" + str(self.border[0]) + "_kccyu" + str(self.border[1]) + "_kccxr" +\
|
||||||
|
str(self.border[2]) + "_kccyd" + str(self.border[3])
|
||||||
if forcepng:
|
if forcepng:
|
||||||
self.image.save(os.path.join(targetdir, os.path.splitext(self.filename)[0] + suffix + ".png"), "PNG",
|
self.image.save(os.path.join(targetdir, os.path.splitext(self.filename)[0] + suffix + ".png"), "PNG",
|
||||||
optimize=1)
|
optimize=1)
|
||||||
@@ -232,6 +233,23 @@ class ComicPage:
|
|||||||
# Quantize is deprecated but new function call it internally anyway...
|
# Quantize is deprecated but new function call it internally anyway...
|
||||||
self.image = self.image.quantize(palette=palImg)
|
self.image = self.image.quantize(palette=palImg)
|
||||||
|
|
||||||
|
def calculateBorder(self, sourceImage):
|
||||||
|
if self.fill == 'white':
|
||||||
|
border = ImageOps.invert(sourceImage.image).getbbox()
|
||||||
|
else:
|
||||||
|
border = sourceImage.image.getbbox()
|
||||||
|
if border is not None:
|
||||||
|
if border[2]-border[0] < self.size[0]:
|
||||||
|
self.noHPV = True
|
||||||
|
if border[3]-border[1] < self.size[1]:
|
||||||
|
self.noVPV = True
|
||||||
|
self.border = [border[0], border[1],
|
||||||
|
sourceImage.image.size[0] - border[2], sourceImage.image.size[1] - border[3]]
|
||||||
|
else:
|
||||||
|
self.border = [0, 0]
|
||||||
|
self.noHPV = True
|
||||||
|
self.noVPV = True
|
||||||
|
|
||||||
def resizeImage(self, upscale=False, stretch=False, bordersColor=None, qualityMode=0):
|
def resizeImage(self, upscale=False, stretch=False, bordersColor=None, qualityMode=0):
|
||||||
# High-quality downscaling filter
|
# High-quality downscaling filter
|
||||||
method = Image.ANTIALIAS
|
method = Image.ANTIALIAS
|
||||||
@@ -239,28 +257,17 @@ class ComicPage:
|
|||||||
fill = bordersColor
|
fill = bordersColor
|
||||||
else:
|
else:
|
||||||
fill = self.fill
|
fill = self.fill
|
||||||
|
# Set target size
|
||||||
if qualityMode == 0:
|
if qualityMode == 0:
|
||||||
size = (self.size[0], self.size[1])
|
size = (self.size[0], self.size[1])
|
||||||
generateBorder = True
|
|
||||||
elif qualityMode == 1:
|
|
||||||
size = (self.panelviewsize[0], self.panelviewsize[1])
|
|
||||||
generateBorder = True
|
|
||||||
else:
|
else:
|
||||||
size = (self.panelviewsize[0], self.panelviewsize[1])
|
size = (self.panelviewsize[0], self.panelviewsize[1])
|
||||||
generateBorder = False
|
# If image is smaller than target size and upscale is off - Just expand it by adding margins
|
||||||
# If image is smaller than screen and upscale is off - Just expand it
|
if self.image.size[0] <= size[0] and self.image.size[1] <= size[1]:
|
||||||
if self.image.size[0] <= self.size[0] and self.image.size[1] <= self.size[1]:
|
|
||||||
if not upscale:
|
if not upscale:
|
||||||
borderw = (self.size[0] - self.image.size[0]) / 2
|
borderw = (size[0] - self.image.size[0]) / 2
|
||||||
borderh = (self.size[1] - self.image.size[1]) / 2
|
borderh = (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 (self.image.size[0]-(2*borderw))*1.5 < self.size[0]:
|
|
||||||
self.noHPV = True
|
|
||||||
if (self.image.size[1]-(2*borderh))*1.5 < self.size[1]:
|
|
||||||
self.noVPV = True
|
|
||||||
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)]
|
|
||||||
return self.image
|
return self.image
|
||||||
else:
|
else:
|
||||||
# Cubic spline interpolation in a 4x4 environment
|
# Cubic spline interpolation in a 4x4 environment
|
||||||
@@ -268,25 +275,9 @@ class ComicPage:
|
|||||||
# If stretching is on - Resize without other considerations
|
# If stretching is on - Resize without other considerations
|
||||||
if stretch:
|
if stretch:
|
||||||
self.image = self.image.resize(size, method)
|
self.image = self.image.resize(size, method)
|
||||||
if generateBorder:
|
|
||||||
if fill == 'white':
|
|
||||||
border = ImageOps.invert(self.image).getbbox()
|
|
||||||
else:
|
|
||||||
border = self.image.getbbox()
|
|
||||||
if border is not None:
|
|
||||||
if (border[2]-border[0])*1.5 < self.size[0]:
|
|
||||||
self.noHPV = True
|
|
||||||
if (border[3]-border[1])*1.5 < self.size[1]:
|
|
||||||
self.noVPV = True
|
|
||||||
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)]
|
|
||||||
else:
|
|
||||||
self.border = [0, 0]
|
|
||||||
self.noHPV = True
|
|
||||||
self.noVPV = True
|
|
||||||
return self.image
|
return self.image
|
||||||
# Otherwise - Upscale/Downscale
|
# Otherwise - Upscale/Downscale
|
||||||
ratioDev = float(self.size[0]) / float(self.size[1])
|
ratioDev = float(size[0]) / float(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:
|
||||||
diff = int(self.image.size[1] * ratioDev) - self.image.size[0]
|
diff = int(self.image.size[1] * ratioDev) - self.image.size[0]
|
||||||
self.image = ImageOps.expand(self.image, border=(diff / 2, 0), fill=fill)
|
self.image = ImageOps.expand(self.image, border=(diff / 2, 0), fill=fill)
|
||||||
@@ -294,22 +285,6 @@ class ComicPage:
|
|||||||
diff = int(self.image.size[0] / ratioDev) - self.image.size[1]
|
diff = int(self.image.size[0] / ratioDev) - self.image.size[1]
|
||||||
self.image = ImageOps.expand(self.image, border=(0, diff / 2), fill=fill)
|
self.image = ImageOps.expand(self.image, border=(0, diff / 2), fill=fill)
|
||||||
self.image = ImageOps.fit(self.image, size, method=method, centering=(0.5, 0.5))
|
self.image = ImageOps.fit(self.image, size, method=method, centering=(0.5, 0.5))
|
||||||
if generateBorder:
|
|
||||||
if fill == 'white':
|
|
||||||
border = ImageOps.invert(self.image).getbbox()
|
|
||||||
else:
|
|
||||||
border = self.image.getbbox()
|
|
||||||
if border is not None:
|
|
||||||
if (border[2]-border[0])*1.5 < self.size[0]:
|
|
||||||
self.noHPV = True
|
|
||||||
if (border[3]-border[1])*1.5 < self.size[1]:
|
|
||||||
self.noVPV = True
|
|
||||||
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)]
|
|
||||||
else:
|
|
||||||
self.border = [0, 0]
|
|
||||||
self.noHPV = True
|
|
||||||
self.noVPV = True
|
|
||||||
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