mirror of
https://github.com/ciromattia/kcc
synced 2025-12-13 09:46:25 +00:00
Tweaked whitespace cropping + other small tweaks
This commit is contained in:
@@ -308,7 +308,7 @@ 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:
|
||||||
img.cropWhiteSpace(10.0)
|
img.cropWhiteSpace()
|
||||||
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)
|
||||||
@@ -1016,6 +1016,8 @@ def main(argv=None, qtGUI=None):
|
|||||||
|
|
||||||
|
|
||||||
def getOutputFilename(srcpath, wantedname, ext, tomeNumber):
|
def getOutputFilename(srcpath, wantedname, ext, tomeNumber):
|
||||||
|
if srcpath[-1] == os.path.sep:
|
||||||
|
srcpath = srcpath[:-1]
|
||||||
if not ext.startswith('.'):
|
if not ext.startswith('.'):
|
||||||
ext = '.' + ext
|
ext = '.' + ext
|
||||||
if wantedname is not None:
|
if wantedname is not None:
|
||||||
|
|||||||
11
kcc/image.py
11
kcc/image.py
@@ -362,27 +362,28 @@ class ComicPage:
|
|||||||
self.image = self.image.crop((0, 0, widthImg, heightImg - diff))
|
self.image = self.image.crop((0, 0, widthImg, heightImg - diff))
|
||||||
return self.image
|
return self.image
|
||||||
|
|
||||||
def cropWhiteSpace(self, threshold):
|
def cropWhiteSpace(self):
|
||||||
if ImageChops.invert(self.image).getbbox() is not None:
|
if ImageChops.invert(self.image).getbbox() is not None:
|
||||||
widthImg, heightImg = self.image.size
|
widthImg, heightImg = self.image.size
|
||||||
delta = 10
|
delta = 10
|
||||||
diff = delta
|
diff = delta
|
||||||
|
fixedThreshold = 0.1
|
||||||
# top
|
# top
|
||||||
while ImageStat.Stat(self.image.crop((0, 0, widthImg, diff))).var[0] < threshold and diff < heightImg:
|
while ImageStat.Stat(self.image.crop((0, 0, widthImg, diff))).var[0] < fixedThreshold and diff < heightImg:
|
||||||
diff += delta
|
diff += delta
|
||||||
diff -= delta
|
diff -= delta
|
||||||
self.image = self.image.crop((0, diff, widthImg, heightImg))
|
self.image = self.image.crop((0, diff, widthImg, heightImg))
|
||||||
widthImg, heightImg = self.image.size
|
widthImg, heightImg = self.image.size
|
||||||
diff = delta
|
diff = delta
|
||||||
# left
|
# left
|
||||||
while ImageStat.Stat(self.image.crop((0, 0, diff, heightImg))).var[0] < threshold and diff < widthImg:
|
while ImageStat.Stat(self.image.crop((0, 0, diff, heightImg))).var[0] < fixedThreshold and diff < widthImg:
|
||||||
diff += delta
|
diff += delta
|
||||||
diff -= delta
|
diff -= delta
|
||||||
self.image = self.image.crop((diff, 0, widthImg, heightImg))
|
self.image = self.image.crop((diff, 0, widthImg, heightImg))
|
||||||
widthImg, heightImg = self.image.size
|
widthImg, heightImg = self.image.size
|
||||||
diff = delta
|
diff = delta
|
||||||
# down
|
# down
|
||||||
while ImageStat.Stat(self.image.crop((0, heightImg - diff, widthImg, heightImg))).var[0] < threshold\
|
while ImageStat.Stat(self.image.crop((0, heightImg - diff, widthImg, heightImg))).var[0] < fixedThreshold\
|
||||||
and diff < heightImg:
|
and diff < heightImg:
|
||||||
diff += delta
|
diff += delta
|
||||||
diff -= delta
|
diff -= delta
|
||||||
@@ -390,7 +391,7 @@ class ComicPage:
|
|||||||
widthImg, heightImg = self.image.size
|
widthImg, heightImg = self.image.size
|
||||||
diff = delta
|
diff = delta
|
||||||
# right
|
# right
|
||||||
while ImageStat.Stat(self.image.crop((widthImg - diff, 0, widthImg, heightImg))).var[0] < threshold\
|
while ImageStat.Stat(self.image.crop((widthImg - diff, 0, widthImg, heightImg))).var[0] < fixedThreshold\
|
||||||
and diff < widthImg:
|
and diff < widthImg:
|
||||||
diff += delta
|
diff += delta
|
||||||
diff -= delta
|
diff -= delta
|
||||||
|
|||||||
Reference in New Issue
Block a user