mirror of
https://github.com/ciromattia/kcc
synced 2025-12-19 04:31:50 +00:00
WebToon splitter improvements
This commit is contained in:
@@ -109,6 +109,7 @@ Options:
|
|||||||
-y HEIGHT, --height=HEIGHT
|
-y HEIGHT, --height=HEIGHT
|
||||||
Height of the target device screen
|
Height of the target device screen
|
||||||
-i, --in-place Overwrite source directory
|
-i, --in-place Overwrite source directory
|
||||||
|
-m, --merge Combine every directory into a single image before splitting
|
||||||
|
|
||||||
OTHER:
|
OTHER:
|
||||||
-d, --debug Create debug file for every splitted image
|
-d, --debug Create debug file for every splitted image
|
||||||
|
|||||||
@@ -953,12 +953,10 @@ def main(argv=None, qtGUI=None):
|
|||||||
path = getWorkFolder(args[0])
|
path = getWorkFolder(args[0])
|
||||||
checkComicInfo(path + "/OEBPS/Images/", args[0])
|
checkComicInfo(path + "/OEBPS/Images/", args[0])
|
||||||
if options.webtoon:
|
if options.webtoon:
|
||||||
if GUI:
|
|
||||||
GUI.emit(QtCore.SIGNAL("progressBarTick"), 'status', 'Splitting images')
|
|
||||||
if options.customheight > 0:
|
if options.customheight > 0:
|
||||||
comic2panel.main(['-y ' + str(options.customheight), '-i', path], qtGUI)
|
comic2panel.main(['-y ' + str(options.customheight), '-i', '-m', path], qtGUI)
|
||||||
else:
|
else:
|
||||||
comic2panel.main(['-y ' + str(image.ProfileData.Profiles[options.profile][1][1]), '-i', path], qtGUI)
|
comic2panel.main(['-y ' + str(image.ProfileData.Profiles[options.profile][1][1]), '-i', '-m', path], qtGUI)
|
||||||
if options.imgproc:
|
if options.imgproc:
|
||||||
print "\nProcessing images..."
|
print "\nProcessing images..."
|
||||||
if GUI:
|
if GUI:
|
||||||
|
|||||||
@@ -69,6 +69,59 @@ def getImageFileName(imgfile):
|
|||||||
return filename
|
return filename
|
||||||
|
|
||||||
|
|
||||||
|
def walkLevel(some_dir, level=1):
|
||||||
|
some_dir = some_dir.rstrip(os.path.sep)
|
||||||
|
assert os.path.isdir(some_dir)
|
||||||
|
num_sep = some_dir.count(os.path.sep)
|
||||||
|
for root, dirs, files in os.walk(some_dir):
|
||||||
|
yield root, dirs, files
|
||||||
|
num_sep_this = root.count(os.path.sep)
|
||||||
|
if num_sep + level <= num_sep_this:
|
||||||
|
del dirs[:]
|
||||||
|
|
||||||
|
|
||||||
|
def mergeDirectory_tick(output):
|
||||||
|
if output:
|
||||||
|
mergeWorkerOutput.append(output)
|
||||||
|
mergeWorkerPool.terminate()
|
||||||
|
if GUI:
|
||||||
|
GUI.emit(QtCore.SIGNAL("progressBarTick"))
|
||||||
|
if not GUI.conversionAlive:
|
||||||
|
mergeWorkerPool.terminate()
|
||||||
|
|
||||||
|
|
||||||
|
def mergeDirectory(work):
|
||||||
|
try:
|
||||||
|
directory = work[0]
|
||||||
|
images = []
|
||||||
|
imagesClear = []
|
||||||
|
sizes = []
|
||||||
|
for root, dirs, files in walkLevel(directory, 0):
|
||||||
|
for name in files:
|
||||||
|
if getImageFileName(name) is not None:
|
||||||
|
images.append([Image.open(os.path.join(root, name)), os.path.join(root, name)])
|
||||||
|
if len(images) > 0:
|
||||||
|
for i in images:
|
||||||
|
sizes.append(i[0].size[0])
|
||||||
|
mw = max(set(sizes), key=sizes.count)
|
||||||
|
for i in images:
|
||||||
|
if i[0].size[0] == mw:
|
||||||
|
i[0] = i[0].convert('RGB')
|
||||||
|
imagesClear.append(i)
|
||||||
|
h = sum(i[0].size[1] for i in imagesClear)
|
||||||
|
result = Image.new('RGB', (mw, h))
|
||||||
|
y = 0
|
||||||
|
for i in imagesClear:
|
||||||
|
result.paste(i[0], (0, y))
|
||||||
|
y += i[0].size[1]
|
||||||
|
for i in imagesClear:
|
||||||
|
os.remove(i[1])
|
||||||
|
savePath = os.path.split(imagesClear[0][1])
|
||||||
|
result.save(os.path.join(savePath[0], os.path.splitext(savePath[1])[0] + '.png'), 'PNG')
|
||||||
|
except StandardError:
|
||||||
|
return str(sys.exc_info()[1])
|
||||||
|
|
||||||
|
|
||||||
def sanitizePanelSize(panel, opt):
|
def sanitizePanelSize(panel, opt):
|
||||||
newPanels = []
|
newPanels = []
|
||||||
if panel[2] > 8 * opt.height:
|
if panel[2] > 8 * opt.height:
|
||||||
@@ -216,7 +269,7 @@ def Copyright():
|
|||||||
|
|
||||||
|
|
||||||
def main(argv=None, qtGUI=None):
|
def main(argv=None, qtGUI=None):
|
||||||
global options, GUI, splitWorkerPool, splitWorkerOutput
|
global options, GUI, splitWorkerPool, splitWorkerOutput, mergeWorkerPool, mergeWorkerOutput
|
||||||
parser = OptionParser(usage="Usage: %prog [options] comic_folder", add_help_option=False)
|
parser = OptionParser(usage="Usage: %prog [options] comic_folder", add_help_option=False)
|
||||||
mainOptions = OptionGroup(parser, "MANDATORY")
|
mainOptions = OptionGroup(parser, "MANDATORY")
|
||||||
otherOptions = OptionGroup(parser, "OTHER")
|
otherOptions = OptionGroup(parser, "OTHER")
|
||||||
@@ -224,6 +277,8 @@ def main(argv=None, qtGUI=None):
|
|||||||
help="Height of the target device screen")
|
help="Height of the target device screen")
|
||||||
mainOptions.add_option("-i", "--in-place", action="store_true", dest="inPlace", default=False,
|
mainOptions.add_option("-i", "--in-place", action="store_true", dest="inPlace", default=False,
|
||||||
help="Overwrite source directory")
|
help="Overwrite source directory")
|
||||||
|
mainOptions.add_option("-m", "--merge", action="store_true", dest="merge", default=False,
|
||||||
|
help="Combine every directory into a single image before splitting")
|
||||||
otherOptions.add_option("-d", "--debug", action="store_true", dest="debug", default=False,
|
otherOptions.add_option("-d", "--debug", action="store_true", dest="debug", default=False,
|
||||||
help="Create debug file for every splitted image")
|
help="Create debug file for every splitted image")
|
||||||
otherOptions.add_option("-h", "--help", action="help",
|
otherOptions.add_option("-h", "--help", action="help",
|
||||||
@@ -249,6 +304,29 @@ def main(argv=None, qtGUI=None):
|
|||||||
pagenumber = 0
|
pagenumber = 0
|
||||||
splitWorkerOutput = []
|
splitWorkerOutput = []
|
||||||
splitWorkerPool = Pool()
|
splitWorkerPool = Pool()
|
||||||
|
if options.merge:
|
||||||
|
directoryNumer = 1
|
||||||
|
mergeWork = []
|
||||||
|
mergeWorkerOutput = []
|
||||||
|
mergeWorkerPool = Pool()
|
||||||
|
mergeWork.append([options.targetDir])
|
||||||
|
for root, dirs, files in os.walk(options.targetDir, False):
|
||||||
|
for directory in dirs:
|
||||||
|
directoryNumer += 1
|
||||||
|
mergeWork.append([os.path.join(root, directory)])
|
||||||
|
if GUI:
|
||||||
|
GUI.emit(QtCore.SIGNAL("progressBarTick"), 'status', 'Combining images')
|
||||||
|
GUI.emit(QtCore.SIGNAL("progressBarTick"), directoryNumer)
|
||||||
|
for i in mergeWork:
|
||||||
|
mergeWorkerPool.apply_async(func=mergeDirectory, args=(i, ), callback=mergeDirectory_tick)
|
||||||
|
mergeWorkerPool.close()
|
||||||
|
mergeWorkerPool.join()
|
||||||
|
if GUI and not GUI.conversionAlive:
|
||||||
|
rmtree(options.targetDir, True)
|
||||||
|
raise UserWarning("Conversion interrupted.")
|
||||||
|
if len(mergeWorkerOutput) > 0:
|
||||||
|
rmtree(options.targetDir, True)
|
||||||
|
raise RuntimeError("One of workers crashed. Cause: " + mergeWorkerOutput[0])
|
||||||
for root, dirs, files in os.walk(options.targetDir, False):
|
for root, dirs, files in os.walk(options.targetDir, False):
|
||||||
for name in files:
|
for name in files:
|
||||||
if getImageFileName(name) is not None:
|
if getImageFileName(name) is not None:
|
||||||
@@ -257,7 +335,9 @@ def main(argv=None, qtGUI=None):
|
|||||||
else:
|
else:
|
||||||
os.remove(os.path.join(root, name))
|
os.remove(os.path.join(root, name))
|
||||||
if GUI:
|
if GUI:
|
||||||
|
GUI.emit(QtCore.SIGNAL("progressBarTick"), 'status', 'Splitting images')
|
||||||
GUI.emit(QtCore.SIGNAL("progressBarTick"), pagenumber)
|
GUI.emit(QtCore.SIGNAL("progressBarTick"), pagenumber)
|
||||||
|
GUI.emit(QtCore.SIGNAL("progressBarTick"))
|
||||||
if len(work) > 0:
|
if len(work) > 0:
|
||||||
for i in work:
|
for i in work:
|
||||||
splitWorkerPool.apply_async(func=splitImage, args=(i, ), callback=splitImage_tick)
|
splitWorkerPool.apply_async(func=splitImage, args=(i, ), callback=splitImage_tick)
|
||||||
|
|||||||
Reference in New Issue
Block a user