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