mirror of
https://github.com/ciromattia/kcc
synced 2025-12-14 02:06:40 +00:00
Webstrip mode improvements
This commit is contained in:
@@ -323,8 +323,9 @@ def getImageFileName(imgfile):
|
|||||||
|
|
||||||
|
|
||||||
def applyImgOptimization(img, isSplit, toRight, options, overrideQuality=5):
|
def applyImgOptimization(img, isSplit, toRight, options, overrideQuality=5):
|
||||||
img.cropWhiteSpace(10.0)
|
if not options.webstrip:
|
||||||
if options.cutpagenumbers:
|
img.cropWhiteSpace(10.0)
|
||||||
|
if options.cutpagenumbers and not options.webstrip:
|
||||||
img.cutPageNumber()
|
img.cutPageNumber()
|
||||||
img.optimizeImage(options.gamma)
|
img.optimizeImage(options.gamma)
|
||||||
if overrideQuality != 5:
|
if overrideQuality != 5:
|
||||||
|
|||||||
@@ -53,6 +53,22 @@ def getImageFileName(imgfile):
|
|||||||
return filename
|
return filename
|
||||||
|
|
||||||
|
|
||||||
|
def getImageFill(histogram):
|
||||||
|
RBGW = []
|
||||||
|
for i in range(256):
|
||||||
|
RBGW.append(histogram[i] + histogram[256 + i] + histogram[512 + i])
|
||||||
|
white = 0
|
||||||
|
black = 0
|
||||||
|
for i in range(245, 256):
|
||||||
|
white += RBGW[i]
|
||||||
|
for i in range(11):
|
||||||
|
black += RBGW[i]
|
||||||
|
if white > black:
|
||||||
|
return 'KCCFW'
|
||||||
|
else:
|
||||||
|
return 'KCCFB'
|
||||||
|
|
||||||
|
|
||||||
def sanitizePanelSize(panel, options):
|
def sanitizePanelSize(panel, options):
|
||||||
newPanels = []
|
newPanels = []
|
||||||
if panel[2] > 1.5 * options.height:
|
if panel[2] > 1.5 * options.height:
|
||||||
@@ -95,19 +111,6 @@ def splitImage(work):
|
|||||||
debugImage = Image.open(os.path.join(path, name))
|
debugImage = Image.open(os.path.join(path, name))
|
||||||
draw = ImageDraw.Draw(debugImage)
|
draw = ImageDraw.Draw(debugImage)
|
||||||
|
|
||||||
# Find fill color
|
|
||||||
white = 0
|
|
||||||
black = 0
|
|
||||||
for i in image.getdata():
|
|
||||||
if i == (255, 255, 255):
|
|
||||||
white += 1
|
|
||||||
elif i == (0, 0, 0):
|
|
||||||
black += 1
|
|
||||||
if white > black:
|
|
||||||
fill = 'KCCFW'
|
|
||||||
else:
|
|
||||||
fill = 'KCCFB'
|
|
||||||
|
|
||||||
# Find panels
|
# Find panels
|
||||||
y1 = 0
|
y1 = 0
|
||||||
y2 = 10
|
y2 = 10
|
||||||
@@ -167,7 +170,8 @@ def splitImage(work):
|
|||||||
panelImg = image.crop([0, panels[panel][0], widthImg, panels[panel][1]])
|
panelImg = image.crop([0, panels[panel][0], widthImg, panels[panel][1]])
|
||||||
newPage.paste(panelImg, (0, targetHeight))
|
newPage.paste(panelImg, (0, targetHeight))
|
||||||
targetHeight += panels[panel][2]
|
targetHeight += panels[panel][2]
|
||||||
newPage.save(os.path.join(path, fileExpanded[0] + '-' + str(pageNumber) + '-' + fill + '.png'), 'PNG')
|
newPage.save(os.path.join(path, fileExpanded[0] + '-' +
|
||||||
|
str(pageNumber) + '-' + getImageFill(newPage.histogram()) + '.png'), 'PNG')
|
||||||
pageNumber += 1
|
pageNumber += 1
|
||||||
os.remove(os.path.join(path, name))
|
os.remove(os.path.join(path, name))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user