mirror of
https://github.com/ciromattia/kcc
synced 2026-07-07 13:35:36 +00:00
Disabled cropping and page number cutting for blank pages (close #43)
This commit is contained in:
@@ -178,6 +178,7 @@ The app relies and includes the following scripts/binaries:
|
|||||||
* Kindle Fire support (color ePub/Mobi)
|
* Kindle Fire support (color ePub/Mobi)
|
||||||
* Panel View support for horizontal content
|
* Panel View support for horizontal content
|
||||||
* Fixed panel order for horizontal pages when --rotate is enabled
|
* Fixed panel order for horizontal pages when --rotate is enabled
|
||||||
|
* Disabled cropping and page number cutting for blank pages
|
||||||
|
|
||||||
## COPYRIGHT
|
## COPYRIGHT
|
||||||
|
|
||||||
|
|||||||
+85
-83
@@ -20,7 +20,7 @@ __copyright__ = '2012-2013, Ciro Mattia Gonano <ciromattia@gmail.com>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from PIL import Image, ImageOps, ImageStat
|
from PIL import Image, ImageOps, ImageStat, ImageChops
|
||||||
|
|
||||||
|
|
||||||
class ImageFlags:
|
class ImageFlags:
|
||||||
@@ -237,93 +237,95 @@ class ComicPage:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def cutPageNumber(self):
|
def cutPageNumber(self):
|
||||||
widthImg, heightImg = self.image.size
|
if ImageChops.invert(self.image).getbbox() is not None:
|
||||||
delta = 2
|
widthImg, heightImg = self.image.size
|
||||||
diff = delta
|
delta = 2
|
||||||
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\
|
|
||||||
and diff < heightImg:
|
|
||||||
diff += delta
|
|
||||||
diff -= delta
|
|
||||||
pageNumberCut1 = diff
|
|
||||||
if diff < delta:
|
|
||||||
diff = delta
|
diff = delta
|
||||||
oldStat = ImageStat.Stat(self.image.crop((0, heightImg - diff, widthImg, heightImg))).var[0]
|
fixedThreshold = 5
|
||||||
diff += delta
|
if ImageStat.Stat(self.image).var[0] < 2 * fixedThreshold:
|
||||||
while ImageStat.Stat(self.image.crop((0, heightImg - diff, widthImg, heightImg))).var[0] - oldStat > 0\
|
return self.image
|
||||||
and diff < heightImg / 4:
|
while ImageStat.Stat(self.image.crop((0, heightImg - diff, widthImg, heightImg))).var[0] < fixedThreshold\
|
||||||
|
and diff < heightImg:
|
||||||
|
diff += delta
|
||||||
|
diff -= delta
|
||||||
|
pageNumberCut1 = diff
|
||||||
|
if diff < delta:
|
||||||
|
diff = delta
|
||||||
oldStat = ImageStat.Stat(self.image.crop((0, heightImg - diff, widthImg, heightImg))).var[0]
|
oldStat = ImageStat.Stat(self.image.crop((0, heightImg - diff, widthImg, heightImg))).var[0]
|
||||||
diff += delta
|
diff += delta
|
||||||
diff -= delta
|
while ImageStat.Stat(self.image.crop((0, heightImg - diff, widthImg, heightImg))).var[0] - oldStat > 0\
|
||||||
pageNumberCut2 = diff
|
and diff < heightImg / 4:
|
||||||
diff += delta
|
oldStat = ImageStat.Stat(self.image.crop((0, heightImg - diff, widthImg, heightImg))).var[0]
|
||||||
oldStat = ImageStat.Stat(self.image.crop((0, heightImg - diff, widthImg, heightImg - pageNumberCut2))).var[0]
|
diff += delta
|
||||||
while ImageStat.Stat(self.image.crop((0, heightImg - diff, widthImg, heightImg - pageNumberCut2))).var[0]\
|
diff -= delta
|
||||||
< fixedThreshold + oldStat and diff < heightImg / 4:
|
pageNumberCut2 = diff
|
||||||
diff += delta
|
diff += delta
|
||||||
diff -= delta
|
oldStat = ImageStat.Stat(self.image.crop((0, heightImg - diff, widthImg, heightImg - pageNumberCut2))).var[0]
|
||||||
pageNumberCut3 = diff
|
while ImageStat.Stat(self.image.crop((0, heightImg - diff, widthImg, heightImg - pageNumberCut2))).var[0]\
|
||||||
delta = 5
|
< fixedThreshold + oldStat and diff < heightImg / 4:
|
||||||
diff = delta
|
diff += delta
|
||||||
while ImageStat.Stat(self.image.crop((0, heightImg - pageNumberCut2, diff, heightImg))).var[0] < fixedThreshold\
|
diff -= delta
|
||||||
and diff < widthImg:
|
pageNumberCut3 = diff
|
||||||
diff += delta
|
delta = 5
|
||||||
diff -= delta
|
diff = delta
|
||||||
pageNumberX1 = diff
|
while ImageStat.Stat(self.image.crop((0, heightImg - pageNumberCut2, diff, heightImg))).var[0] < fixedThreshold\
|
||||||
diff = delta
|
and diff < widthImg:
|
||||||
while ImageStat.Stat(self.image.crop((widthImg - diff, heightImg - pageNumberCut2,
|
diff += delta
|
||||||
widthImg, heightImg))).var[0] < fixedThreshold and diff < widthImg:
|
diff -= delta
|
||||||
diff += delta
|
pageNumberX1 = diff
|
||||||
diff -= delta
|
diff = delta
|
||||||
pageNumberX2 = widthImg - diff
|
while ImageStat.Stat(self.image.crop((widthImg - diff, heightImg - pageNumberCut2,
|
||||||
if pageNumberCut3 - pageNumberCut1 > 2 * delta\
|
widthImg, heightImg))).var[0] < fixedThreshold and diff < widthImg:
|
||||||
and float(pageNumberX2 - pageNumberX1) / float(pageNumberCut2 - pageNumberCut1) <= 9.0\
|
diff += delta
|
||||||
and ImageStat.Stat(self.image.crop((0, heightImg - pageNumberCut3, widthImg, heightImg))).var[0]\
|
diff -= delta
|
||||||
/ ImageStat.Stat(self.image).var[0] < 0.1\
|
pageNumberX2 = widthImg - diff
|
||||||
and pageNumberCut3 < heightImg / 4 - delta:
|
if pageNumberCut3 - pageNumberCut1 > 2 * delta\
|
||||||
diff = pageNumberCut3
|
and float(pageNumberX2 - pageNumberX1) / float(pageNumberCut2 - pageNumberCut1) <= 9.0\
|
||||||
else:
|
and ImageStat.Stat(self.image.crop((0, heightImg - pageNumberCut3, widthImg, heightImg))).var[0]\
|
||||||
diff = pageNumberCut1
|
/ ImageStat.Stat(self.image).var[0] < 0.1\
|
||||||
self.image = self.image.crop((0, 0, widthImg, heightImg - diff))
|
and pageNumberCut3 < heightImg / 4 - delta:
|
||||||
|
diff = pageNumberCut3
|
||||||
|
else:
|
||||||
|
diff = pageNumberCut1
|
||||||
|
self.image = self.image.crop((0, 0, widthImg, heightImg - diff))
|
||||||
return self.image
|
return self.image
|
||||||
|
|
||||||
def cropWhiteSpace(self, threshold):
|
def cropWhiteSpace(self, threshold):
|
||||||
widthImg, heightImg = self.image.size
|
if ImageChops.invert(self.image).getbbox() is not None:
|
||||||
delta = 10
|
widthImg, heightImg = self.image.size
|
||||||
diff = delta
|
delta = 10
|
||||||
# top
|
diff = delta
|
||||||
while ImageStat.Stat(self.image.crop((0, 0, widthImg, diff))).var[0] < threshold and diff < heightImg:
|
# top
|
||||||
diff += delta
|
while ImageStat.Stat(self.image.crop((0, 0, widthImg, diff))).var[0] < threshold and diff < heightImg:
|
||||||
diff -= delta
|
diff += delta
|
||||||
# print "Top crop: %s"%diff
|
diff -= delta
|
||||||
self.image = self.image.crop((0, diff, widthImg, heightImg))
|
# print "Top crop: %s"%diff
|
||||||
widthImg, heightImg = self.image.size
|
self.image = self.image.crop((0, diff, widthImg, heightImg))
|
||||||
diff = delta
|
widthImg, heightImg = self.image.size
|
||||||
# left
|
diff = delta
|
||||||
while ImageStat.Stat(self.image.crop((0, 0, diff, heightImg))).var[0] < threshold and diff < widthImg:
|
# left
|
||||||
diff += delta
|
while ImageStat.Stat(self.image.crop((0, 0, diff, heightImg))).var[0] < threshold and diff < widthImg:
|
||||||
diff -= delta
|
diff += delta
|
||||||
# print "Left crop: %s"%diff
|
diff -= delta
|
||||||
self.image = self.image.crop((diff, 0, widthImg, heightImg))
|
# print "Left crop: %s"%diff
|
||||||
widthImg, heightImg = self.image.size
|
self.image = self.image.crop((diff, 0, widthImg, heightImg))
|
||||||
diff = delta
|
widthImg, heightImg = self.image.size
|
||||||
# down
|
diff = delta
|
||||||
while ImageStat.Stat(self.image.crop((0, heightImg - diff, widthImg, heightImg))).var[0] < threshold\
|
# down
|
||||||
and diff < heightImg:
|
while ImageStat.Stat(self.image.crop((0, heightImg - diff, widthImg, heightImg))).var[0] < threshold\
|
||||||
diff += delta
|
and diff < heightImg:
|
||||||
diff -= delta
|
diff += delta
|
||||||
# print "Down crop: %s"%diff
|
diff -= delta
|
||||||
self.image = self.image.crop((0, 0, widthImg, heightImg - diff))
|
# print "Down crop: %s"%diff
|
||||||
widthImg, heightImg = self.image.size
|
self.image = self.image.crop((0, 0, widthImg, heightImg - diff))
|
||||||
diff = delta
|
widthImg, heightImg = self.image.size
|
||||||
# right
|
diff = delta
|
||||||
while ImageStat.Stat(self.image.crop((widthImg - diff, 0, widthImg, heightImg))).var[0] < threshold\
|
# right
|
||||||
and diff < widthImg:
|
while ImageStat.Stat(self.image.crop((widthImg - diff, 0, widthImg, heightImg))).var[0] < threshold\
|
||||||
diff += delta
|
and diff < widthImg:
|
||||||
diff -= delta
|
diff += delta
|
||||||
# print "Right crop: %s"%diff
|
diff -= delta
|
||||||
self.image = self.image.crop((0, 0, widthImg - diff, heightImg))
|
# print "Right crop: %s"%diff
|
||||||
# print "New size: %sx%s"%(self.image.size[0],self.image.size[1])
|
self.image = self.image.crop((0, 0, widthImg - diff, heightImg))
|
||||||
|
# print "New size: %sx%s"%(self.image.size[0],self.image.size[1])
|
||||||
return self.image
|
return self.image
|
||||||
|
|||||||
Reference in New Issue
Block a user