mirror of
https://github.com/ciromattia/kcc
synced 2026-10-05 09:02:32 +00:00
Yet another refactoring of resizeImage
I hope all bugs are dead this time!
This commit is contained in:
+9
-4
@@ -222,6 +222,7 @@ def buildOPF(profile, dstdir, title, filelist, cover=None):
|
|||||||
f.write("<item id=\"blank-page" + str(splitCountUsed) +
|
f.write("<item id=\"blank-page" + str(splitCountUsed) +
|
||||||
"\" href=\"Text/blank.html\" media-type=\"application/xhtml+xml\"/>\n")
|
"\" href=\"Text/blank.html\" media-type=\"application/xhtml+xml\"/>\n")
|
||||||
splitCountUsed += 1
|
splitCountUsed += 1
|
||||||
|
f.write("<item id=\"css\" href=\"Text/style.css\" media-type=\"text/css\"/>\n")
|
||||||
f.write("</manifest>\n<spine toc=\"ncx\">\n")
|
f.write("</manifest>\n<spine toc=\"ncx\">\n")
|
||||||
splitCountUsed = 1
|
splitCountUsed = 1
|
||||||
for entry in reflist:
|
for entry in reflist:
|
||||||
@@ -289,11 +290,11 @@ def isInFilelist(filename, filelist):
|
|||||||
return seen
|
return seen
|
||||||
|
|
||||||
|
|
||||||
def applyImgOptimization(img, isSplit=False):
|
def applyImgOptimization(img, isSplit=False, toRight=False):
|
||||||
img.cropWhiteSpace(10.0)
|
img.cropWhiteSpace(10.0)
|
||||||
if options.cutpagenumbers:
|
if options.cutpagenumbers:
|
||||||
img.cutPageNumber()
|
img.cutPageNumber()
|
||||||
img.resizeImage(options.upscale, options.stretch, options.black_borders, isSplit, options.landscapemode,
|
img.resizeImage(options.upscale, options.stretch, options.black_borders, isSplit, toRight, options.landscapemode,
|
||||||
options.nopanelviewhq)
|
options.nopanelviewhq)
|
||||||
img.optimizeImage(options.gamma)
|
img.optimizeImage(options.gamma)
|
||||||
if not options.notquantize:
|
if not options.notquantize:
|
||||||
@@ -323,18 +324,22 @@ def dirImgProcess(path):
|
|||||||
if options.verbose:
|
if options.verbose:
|
||||||
print "Splitted " + afile
|
print "Splitted " + afile
|
||||||
if options.righttoleft:
|
if options.righttoleft:
|
||||||
|
toRight1 = False
|
||||||
|
toRight2 = True
|
||||||
if facing == "left":
|
if facing == "left":
|
||||||
splitCount += 1
|
splitCount += 1
|
||||||
facing = "right"
|
facing = "right"
|
||||||
else:
|
else:
|
||||||
|
toRight1 = True
|
||||||
|
toRight2 = False
|
||||||
if facing == "right":
|
if facing == "right":
|
||||||
splitCount += 1
|
splitCount += 1
|
||||||
facing = "left"
|
facing = "left"
|
||||||
img0 = image.ComicPage(split[0], options.profile)
|
img0 = image.ComicPage(split[0], options.profile)
|
||||||
applyImgOptimization(img0, True)
|
applyImgOptimization(img0, True, toRight1)
|
||||||
img0.saveToDir(dirpath, options.notquantize)
|
img0.saveToDir(dirpath, options.notquantize)
|
||||||
img1 = image.ComicPage(split[1], options.profile)
|
img1 = image.ComicPage(split[1], options.profile)
|
||||||
applyImgOptimization(img1, True)
|
applyImgOptimization(img1, True, toRight2)
|
||||||
img1.saveToDir(dirpath, options.notquantize)
|
img1.saveToDir(dirpath, options.notquantize)
|
||||||
else:
|
else:
|
||||||
if facing == "right":
|
if facing == "right":
|
||||||
|
|||||||
+24
-19
@@ -143,39 +143,44 @@ class ComicPage:
|
|||||||
palImg.putpalette(self.palette)
|
palImg.putpalette(self.palette)
|
||||||
self.image = self.image.quantize(palette=palImg)
|
self.image = self.image.quantize(palette=palImg)
|
||||||
|
|
||||||
def resizeImage(self, upscale=False, stretch=False, black_borders=False, isSplit=False, landscapeMode=False,
|
def resizeImage(self, upscale=False, stretch=False, black_borders=False, isSplit=False, toRight=False,
|
||||||
noPanelViewHQ=False):
|
landscapeMode=False, noPanelViewHQ=False):
|
||||||
method = Image.ANTIALIAS
|
method = Image.ANTIALIAS
|
||||||
if black_borders:
|
if black_borders:
|
||||||
fill = 'black'
|
fill = 'black'
|
||||||
else:
|
else:
|
||||||
fill = 'white'
|
fill = 'white'
|
||||||
if not noPanelViewHQ:
|
if noPanelViewHQ:
|
||||||
size = (self.panelviewsize[0], self.panelviewsize[1])
|
|
||||||
else:
|
|
||||||
size = (self.size[0], self.size[1])
|
size = (self.size[0], self.size[1])
|
||||||
|
else:
|
||||||
|
size = (self.panelviewsize[0], self.panelviewsize[1])
|
||||||
|
if isSplit and landscapeMode:
|
||||||
|
upscale = True
|
||||||
if self.image.size[0] <= self.size[0] and self.image.size[1] <= self.size[1]:
|
if self.image.size[0] <= self.size[0] and self.image.size[1] <= self.size[1]:
|
||||||
if not upscale:
|
if not upscale:
|
||||||
if isSplit and landscapeMode:
|
borderw = (self.size[0] - self.image.size[0]) / 2
|
||||||
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=(0, borderh), fill=fill)
|
self.image = ImageOps.expand(self.image, border=(borderw, borderh), fill=fill)
|
||||||
method = Image.BILINEAR
|
return self.image
|
||||||
else:
|
|
||||||
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
|
|
||||||
else:
|
else:
|
||||||
method = Image.BILINEAR
|
method = Image.BILINEAR
|
||||||
if stretch:
|
if stretch: # if stretching call directly resize() without other considerations.
|
||||||
self.image = self.image.resize(self.size, method)
|
self.image = self.image.resize(size, method)
|
||||||
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:
|
||||||
diff = int(self.image.size[1] * ratioDev) - self.image.size[0]
|
|
||||||
if isSplit and landscapeMode:
|
if isSplit and landscapeMode:
|
||||||
diff = 2
|
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)
|
||||||
|
tempImg = Image.new(self.image.mode, (self.image.size[0] + diff, self.image.size[1]), fill)
|
||||||
|
if toRight:
|
||||||
|
tempImg.paste(self.image, (diff, 0))
|
||||||
|
else:
|
||||||
|
tempImg.paste(self.image, (0, 0))
|
||||||
|
self.image = tempImg
|
||||||
|
else:
|
||||||
|
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:
|
elif (float(self.image.size[0]) / float(self.image.size[1])) > ratioDev:
|
||||||
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user