mirror of
https://github.com/ciromattia/kcc
synced 2026-01-02 11:29:33 +00:00
Panel View support overhaul - Round 2
This commit is contained in:
@@ -142,35 +142,35 @@ def buildHTML(path, imgfile):
|
||||
xr = borders[2].lstrip("0")
|
||||
yd = borders[3].lstrip("0")
|
||||
if xl != "":
|
||||
xl = "-" + str(xl) + "px"
|
||||
xl = "-" + str(float(xl)/100) + "%"
|
||||
else:
|
||||
xl = "0px"
|
||||
xl = "0%"
|
||||
if xr != "":
|
||||
xr = "-" + str(xr) + "px"
|
||||
xr = "-" + str(float(xr)/100) + "%"
|
||||
else:
|
||||
xr = "0px"
|
||||
xr = "0%"
|
||||
if yu != "":
|
||||
yu = "-" + str(yu) + "px"
|
||||
yu = "-" + str(float(yu)/100) + "%"
|
||||
else:
|
||||
yu = "0px"
|
||||
yu = "0%"
|
||||
if yd != "":
|
||||
yd = "-" + str(yd) + "px"
|
||||
yd = "-" + str(float(yd)/100) + "%"
|
||||
else:
|
||||
yd = "0px"
|
||||
yd = "0%"
|
||||
else:
|
||||
xl = "0px"
|
||||
yu = "0px"
|
||||
xr = "0px"
|
||||
yd = "0px"
|
||||
xl = "0%"
|
||||
yu = "0%"
|
||||
xr = "0%"
|
||||
yd = "0%"
|
||||
boxStyles = {"BoxTL": "left:" + xl + ";top:" + yu + ";",
|
||||
"BoxTR": "right:" + xr + ";top:" + yu + ";",
|
||||
"BoxBL": "left:" + xl + ";bottom:" + yd + ";",
|
||||
"BoxBR": "right:" + xr + ";bottom:" + yd + ";",
|
||||
"BoxT": "left:-25%;top:" + yu + ";",
|
||||
"BoxB": "left:-25%;bottom:" + yd + ";",
|
||||
"BoxL": "left:" + xl + ";top:-25%;",
|
||||
"BoxR": "right:" + xr + ";top:-25%;",
|
||||
"BoxC": "right:-25%;top:-25%;"
|
||||
"BoxT": "left:" + xl + ";top:" + yu + ";",
|
||||
"BoxB": "left:" + xl + ";bottom:" + yd + ";",
|
||||
"BoxL": "left:" + xl + ";top:" + yu + ";",
|
||||
"BoxR": "right:" + xr + ";top:" + yu + ";",
|
||||
"BoxC": "left:" + xl + ";top:" + yu + ";"
|
||||
}
|
||||
for box in boxes:
|
||||
f.writelines(["<div id=\"" + box + "-Panel-Parent\" class=\"target-mag-parent\"><div id=\"",
|
||||
@@ -321,6 +321,8 @@ def applyImgOptimization(img, opt, hqImage=None):
|
||||
img.calculateBorder(hqImage)
|
||||
else:
|
||||
img.resizeImage(opt.upscale, opt.stretch, opt.bordersColor, opt.quality)
|
||||
if opt.panelview and opt.quality != 2:
|
||||
img.calculateBorder(img)
|
||||
if opt.forcepng and not opt.forcecolor:
|
||||
img.quantizeImage()
|
||||
|
||||
|
||||
48
kcc/image.py
48
kcc/image.py
@@ -233,26 +233,34 @@ class ComicPage:
|
||||
# Quantize is deprecated but new function call it internally anyway...
|
||||
self.image = self.image.quantize(palette=palImg)
|
||||
|
||||
def calculateBorderPercent(self, x, img, isWidth):
|
||||
if isWidth:
|
||||
return int(round(float(x)/float(img.image.size[0]), 4) * 10000 * 1.5)
|
||||
else:
|
||||
return int(round(float(x)/float(img.image.size[1]), 4) * 10000 * 1.5)
|
||||
|
||||
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.border = [self.calculateBorderPercent(border[0], sourceImage, True),
|
||||
self.calculateBorderPercent(border[1], sourceImage, False),
|
||||
self.calculateBorderPercent((sourceImage.image.size[0] - border[2]), sourceImage, True),
|
||||
self.calculateBorderPercent((sourceImage.image.size[1] - border[3]), sourceImage, False)]
|
||||
if int((border[2] - border[0]) * 1.5) < self.size[0]:
|
||||
self.noHPV = True
|
||||
if border[3]-border[1] < self.size[1]:
|
||||
self.border[0] /= 2
|
||||
if int((border[3] - border[1]) * 1.5) < self.size[1]:
|
||||
self.noVPV = True
|
||||
self.border = [border[0], border[1],
|
||||
sourceImage.image.size[0] - border[2], sourceImage.image.size[1] - border[3]]
|
||||
self.border[1] /= 2
|
||||
else:
|
||||
self.border = [0, 0]
|
||||
self.border = [0, 0, 0, 0]
|
||||
self.noHPV = True
|
||||
self.noVPV = True
|
||||
|
||||
def resizeImage(self, upscale=False, stretch=False, bordersColor=None, qualityMode=0):
|
||||
# High-quality downscaling filter
|
||||
method = Image.ANTIALIAS
|
||||
if bordersColor:
|
||||
fill = bordersColor
|
||||
else:
|
||||
@@ -262,28 +270,32 @@ class ComicPage:
|
||||
size = (self.size[0], self.size[1])
|
||||
else:
|
||||
size = (self.panelviewsize[0], self.panelviewsize[1])
|
||||
# If image is smaller than target size and upscale is off - Just expand it by adding margins
|
||||
if self.image.size[0] <= size[0] and self.image.size[1] <= size[1]:
|
||||
if not upscale:
|
||||
borderw = (size[0] - self.image.size[0]) / 2
|
||||
borderh = (size[1] - self.image.size[1]) / 2
|
||||
self.image = ImageOps.expand(self.image, border=(borderw, borderh), fill=fill)
|
||||
return self.image
|
||||
else:
|
||||
# Cubic spline interpolation in a 4x4 environment
|
||||
method = Image.BICUBIC
|
||||
# If image is smaller than device resolution and upscale is off - Just expand it by adding margins
|
||||
if self.image.size[0] <= self.size[0] and self.image.size[1] <= self.size[1] and not upscale:
|
||||
borderw = (self.size[0] - self.image.size[0]) / 2
|
||||
borderh = (self.size[1] - self.image.size[1]) / 2
|
||||
self.image = ImageOps.expand(self.image, border=(borderw, borderh), fill=fill)
|
||||
return self.image
|
||||
# If stretching is on - Resize without other considerations
|
||||
if stretch:
|
||||
if self.image.size[0] <= size[0] and self.image.size[1] <= size[1]:
|
||||
method = Image.BICUBIC
|
||||
else:
|
||||
method = Image.ANTIALIAS
|
||||
self.image = self.image.resize(size, method)
|
||||
return self.image
|
||||
# Otherwise - Upscale/Downscale
|
||||
ratioDev = float(size[0]) / float(size[1])
|
||||
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]
|
||||
self.image = ImageOps.expand(self.image, border=(diff / 2, 0), fill=fill)
|
||||
elif (float(self.image.size[0]) / float(self.image.size[1])) > ratioDev:
|
||||
diff = int(self.image.size[0] / ratioDev) - self.image.size[1]
|
||||
self.image = ImageOps.expand(self.image, border=(0, diff / 2), fill=fill)
|
||||
if self.image.size[0] <= size[0] and self.image.size[1] <= size[1]:
|
||||
method = Image.BICUBIC
|
||||
else:
|
||||
method = Image.ANTIALIAS
|
||||
self.image = ImageOps.fit(self.image, size, method=method, centering=(0.5, 0.5))
|
||||
return self.image
|
||||
|
||||
|
||||
Reference in New Issue
Block a user