mirror of
https://github.com/ciromattia/kcc
synced 2026-10-20 16:32:31 +00:00
comic2panel: Autodetect border color
This commit is contained in:
+14
-1
@@ -89,6 +89,19 @@ 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
|
||||||
@@ -148,7 +161,7 @@ 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) + '.png'), 'PNG')
|
newPage.save(os.path.join(path, fileExpanded[0] + '-' + str(pageNumber) + '-' + fill + '.png'), 'PNG')
|
||||||
pageNumber += 1
|
pageNumber += 1
|
||||||
print ".",
|
print ".",
|
||||||
os.remove(os.path.join(path, name))
|
os.remove(os.path.join(path, name))
|
||||||
|
|||||||
+12
-7
@@ -115,6 +115,7 @@ class ComicPage:
|
|||||||
# Detect corrupted files - Phase 2
|
# Detect corrupted files - Phase 2
|
||||||
try:
|
try:
|
||||||
self.origFileName = source
|
self.origFileName = source
|
||||||
|
self.filename = os.path.basename(self.origFileName)
|
||||||
self.image = Image.open(source)
|
self.image = Image.open(source)
|
||||||
except IOError:
|
except IOError:
|
||||||
raise RuntimeError('Cannot read image file %s' % source)
|
raise RuntimeError('Cannot read image file %s' % source)
|
||||||
@@ -134,7 +135,6 @@ class ComicPage:
|
|||||||
self.image = self.image.convert('RGB')
|
self.image = self.image.convert('RGB')
|
||||||
|
|
||||||
def saveToDir(self, targetdir, forcepng, color, wipe, suffix=None):
|
def saveToDir(self, targetdir, forcepng, color, wipe, suffix=None):
|
||||||
filename = os.path.basename(self.origFileName)
|
|
||||||
try:
|
try:
|
||||||
if not color:
|
if not color:
|
||||||
self.image = self.image.convert('L') # convert to grayscale
|
self.image = self.image.convert('L') # convert to grayscale
|
||||||
@@ -143,13 +143,13 @@ class ComicPage:
|
|||||||
else:
|
else:
|
||||||
suffix = ""
|
suffix = ""
|
||||||
if wipe:
|
if wipe:
|
||||||
os.remove(os.path.join(targetdir, filename))
|
os.remove(os.path.join(targetdir, self.filename))
|
||||||
else:
|
else:
|
||||||
suffix += "_kcchq"
|
suffix += "_kcchq"
|
||||||
if forcepng:
|
if forcepng:
|
||||||
self.image.save(os.path.join(targetdir, os.path.splitext(filename)[0] + suffix + ".png"), "PNG")
|
self.image.save(os.path.join(targetdir, os.path.splitext(self.filename)[0] + suffix + ".png"), "PNG")
|
||||||
else:
|
else:
|
||||||
self.image.save(os.path.join(targetdir, os.path.splitext(filename)[0] + suffix + ".jpg"), "JPEG")
|
self.image.save(os.path.join(targetdir, os.path.splitext(self.filename)[0] + suffix + ".jpg"), "JPEG")
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
raise RuntimeError('Cannot write image in directory %s: %s' % (targetdir, e))
|
raise RuntimeError('Cannot write image in directory %s: %s' % (targetdir, e))
|
||||||
|
|
||||||
@@ -174,10 +174,15 @@ class ComicPage:
|
|||||||
def resizeImage(self, upscale=False, stretch=False, black_borders=False, isSplit=False, toRight=False,
|
def resizeImage(self, upscale=False, stretch=False, black_borders=False, isSplit=False, toRight=False,
|
||||||
landscapeMode=False, qualityMode=0):
|
landscapeMode=False, qualityMode=0):
|
||||||
method = Image.ANTIALIAS
|
method = Image.ANTIALIAS
|
||||||
if black_borders:
|
if '-KCCFW' in str(self.filename):
|
||||||
|
fill = 'white'
|
||||||
|
elif '-KCCFB' in str(self.filename):
|
||||||
fill = 'black'
|
fill = 'black'
|
||||||
else:
|
else:
|
||||||
fill = 'white'
|
if black_borders:
|
||||||
|
fill = 'black'
|
||||||
|
else:
|
||||||
|
fill = 'white'
|
||||||
if qualityMode == 0:
|
if qualityMode == 0:
|
||||||
size = (self.size[0], self.size[1])
|
size = (self.size[0], self.size[1])
|
||||||
else:
|
else:
|
||||||
@@ -234,7 +239,7 @@ class ComicPage:
|
|||||||
# source is portrait and target is landscape, so split by the height
|
# source is portrait and target is landscape, so split by the height
|
||||||
leftbox = (0, 0, width, height / 2)
|
leftbox = (0, 0, width, height / 2)
|
||||||
rightbox = (0, height / 2, width, height)
|
rightbox = (0, height / 2, width, height)
|
||||||
filename = os.path.splitext(os.path.basename(self.origFileName))
|
filename = os.path.splitext(self.filename)
|
||||||
fileone = targetdir + '/' + filename[0] + '_kcca' + filename[1]
|
fileone = targetdir + '/' + filename[0] + '_kcca' + filename[1]
|
||||||
filetwo = targetdir + '/' + filename[0] + '_kccb' + filename[1]
|
filetwo = targetdir + '/' + filename[0] + '_kccb' + filename[1]
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user