mirror of
https://github.com/ciromattia/kcc
synced 2026-01-27 23:47:41 +00:00
Added cropping options (close #172)
This commit is contained in:
@@ -545,10 +545,10 @@ def imgFileProcessing(work):
|
||||
workImg = image.ComicPageParser((dirpath, afile), opt)
|
||||
for i in workImg.payload:
|
||||
img = image.ComicPage(i[0], i[1], i[2], i[3], i[4], opt)
|
||||
if not opt.webtoon:
|
||||
img.cropWhiteSpace()
|
||||
if opt.cutpagenumbers and not opt.webtoon:
|
||||
img.cutPageNumber()
|
||||
if opt.cropping > 0 and not opt.webtoon:
|
||||
img.cropWhiteSpace(opt.croppingp)
|
||||
if opt.cropping == 2 and not opt.webtoon:
|
||||
img.cutPageNumber(opt.croppingpn)
|
||||
img.autocontrastImage()
|
||||
img.resizeImage()
|
||||
if opt.forcepng and not opt.forcecolor:
|
||||
@@ -989,8 +989,12 @@ def makeParser():
|
||||
help="Don't convert images to grayscale")
|
||||
processingOptions.add_option("--forcepng", action="store_true", dest="forcepng", default=False,
|
||||
help="Create PNG files instead JPEG")
|
||||
processingOptions.add_option("--nocutpagenumbers", action="store_false", dest="cutpagenumbers", default=True,
|
||||
help="Don't try to cut page numbers from images")
|
||||
processingOptions.add_option("--cropping", type="int", dest="cropping", default="2",
|
||||
help="Set cropping mode. 0: Disabled 1: Margins 2: Margins + page numbers [Default=2]")
|
||||
processingOptions.add_option("--croppingpower", type="float", dest="croppingp", default="0.1",
|
||||
help="Set margin cropping threshold [Default=0.1]")
|
||||
processingOptions.add_option("--croppingpowerpage", type="float", dest="croppingpn", default="5.0",
|
||||
help="Set page number cropping threshold [Default=5.0]")
|
||||
|
||||
customProfileOptions.add_option("--customwidth", type="int", dest="customwidth", default=0,
|
||||
help="Replace screen width provided by device profile")
|
||||
|
||||
@@ -316,12 +316,11 @@ class ComicPage:
|
||||
if self.image.size[0] > size[0] or self.image.size[1] > size[1]:
|
||||
self.image.thumbnail(size, Image.LANCZOS)
|
||||
|
||||
def cutPageNumber(self):
|
||||
def cutPageNumber(self, fixedThreshold):
|
||||
if ImageChops.invert(self.image).getbbox() is not None:
|
||||
widthImg, heightImg = self.image.size
|
||||
delta = 2
|
||||
diff = delta
|
||||
fixedThreshold = 5
|
||||
if ImageStat.Stat(self.image).var[0] < 2 * fixedThreshold:
|
||||
return self.image
|
||||
while ImageStat.Stat(self.image.crop((0, heightImg - diff, widthImg, heightImg))).var[0] < fixedThreshold\
|
||||
@@ -370,12 +369,11 @@ class ComicPage:
|
||||
diff = pageNumberCut1
|
||||
self.image = self.image.crop((0, 0, widthImg, heightImg - diff))
|
||||
|
||||
def cropWhiteSpace(self):
|
||||
def cropWhiteSpace(self, fixedThreshold):
|
||||
if ImageChops.invert(self.image).getbbox() is not None:
|
||||
widthImg, heightImg = self.image.size
|
||||
delta = 10
|
||||
diff = delta
|
||||
fixedThreshold = 0.1
|
||||
# top
|
||||
while ImageStat.Stat(self.image.crop((0, 0, widthImg, diff))).var[0] < fixedThreshold and diff < heightImg:
|
||||
diff += delta
|
||||
|
||||
Reference in New Issue
Block a user