mirror of
https://github.com/ciromattia/kcc
synced 2025-12-13 17:56:30 +00:00
Image flags are not part of filename anymore
This commit is contained in:
@@ -45,22 +45,22 @@ from . import cbxarchive
|
|||||||
from . import pdfjpgextract
|
from . import pdfjpgextract
|
||||||
|
|
||||||
|
|
||||||
def buildHTML(path, imgfile):
|
def buildHTML(path, imgfile, imgfilepath):
|
||||||
filename = getImageFileName(imgfile)
|
filename = getImageFileName(imgfile)
|
||||||
if filename is not None:
|
if filename is not None:
|
||||||
if "-kccrot" in str(filename):
|
if "Rotated" in theGreatIndex[imgfilepath]:
|
||||||
rotatedPage = True
|
rotatedPage = True
|
||||||
else:
|
else:
|
||||||
rotatedPage = False
|
rotatedPage = False
|
||||||
if "-kccnpv" in str(filename):
|
if "NoPanelView" in theGreatIndex[imgfilepath]:
|
||||||
noPV = True
|
noPV = True
|
||||||
else:
|
else:
|
||||||
noPV = False
|
noPV = False
|
||||||
if "-kccnh" in str(filename):
|
if "NoHorizontalPanelView" in theGreatIndex[imgfilepath]:
|
||||||
noHorizontalPV = True
|
noHorizontalPV = True
|
||||||
else:
|
else:
|
||||||
noHorizontalPV = False
|
noHorizontalPV = False
|
||||||
if "-kccnv" in str(filename):
|
if "NoVerticalPanelView" in theGreatIndex[imgfilepath]:
|
||||||
noVerticalPV = True
|
noVerticalPV = True
|
||||||
else:
|
else:
|
||||||
noVerticalPV = False
|
noVerticalPV = False
|
||||||
@@ -133,39 +133,11 @@ def buildHTML(path, imgfile):
|
|||||||
"}'></a></div>\n"])
|
"}'></a></div>\n"])
|
||||||
if options.quality == 2:
|
if options.quality == 2:
|
||||||
imgfilepv = str.split(imgfile, ".")
|
imgfilepv = str.split(imgfile, ".")
|
||||||
imgfilepv[0] = imgfilepv[0].split("-kccxl")[0].replace("-kccnh", "").replace("-kccnv", "")
|
imgfilepv[0] += "-hq"
|
||||||
imgfilepv[0] += "-kcchq"
|
|
||||||
imgfilepv = ".".join(imgfilepv)
|
imgfilepv = ".".join(imgfilepv)
|
||||||
else:
|
else:
|
||||||
imgfilepv = imgfile
|
imgfilepv = imgfile
|
||||||
if "-kccxl" in filename[0]:
|
xl, yu, xr, yd = checkMargins(imgfilepath)
|
||||||
borders = filename[0].split('-kccxl')[1]
|
|
||||||
borders = re.findall('[0-9]{1,6}', borders)
|
|
||||||
xl = borders[0].lstrip("0")
|
|
||||||
yu = borders[1].lstrip("0")
|
|
||||||
xr = borders[2].lstrip("0")
|
|
||||||
yd = borders[3].lstrip("0")
|
|
||||||
if xl != "":
|
|
||||||
xl = "-" + str(float(xl)/100) + "%"
|
|
||||||
else:
|
|
||||||
xl = "0%"
|
|
||||||
if xr != "":
|
|
||||||
xr = "-" + str(float(xr)/100) + "%"
|
|
||||||
else:
|
|
||||||
xr = "0%"
|
|
||||||
if yu != "":
|
|
||||||
yu = "-" + str(float(yu)/100) + "%"
|
|
||||||
else:
|
|
||||||
yu = "0%"
|
|
||||||
if yd != "":
|
|
||||||
yd = "-" + str(float(yd)/100) + "%"
|
|
||||||
else:
|
|
||||||
yd = "0%"
|
|
||||||
else:
|
|
||||||
xl = "0%"
|
|
||||||
yu = "0%"
|
|
||||||
xr = "0%"
|
|
||||||
yd = "0%"
|
|
||||||
boxStyles = {"BoxTL": "left:" + xl + ";top:" + yu + ";",
|
boxStyles = {"BoxTL": "left:" + xl + ";top:" + yu + ";",
|
||||||
"BoxTR": "right:" + xr + ";top:" + yu + ";",
|
"BoxTR": "right:" + xr + ";top:" + yu + ";",
|
||||||
"BoxBL": "left:" + xl + ";bottom:" + yd + ";",
|
"BoxBL": "left:" + xl + ";bottom:" + yd + ";",
|
||||||
@@ -187,6 +159,34 @@ def buildHTML(path, imgfile):
|
|||||||
return path, imgfile
|
return path, imgfile
|
||||||
|
|
||||||
|
|
||||||
|
def checkMargins(path):
|
||||||
|
for flag in theGreatIndex[path]:
|
||||||
|
if "Margins-" in flag:
|
||||||
|
flag = flag.split('-')
|
||||||
|
xl = flag[1]
|
||||||
|
yu = flag[2]
|
||||||
|
xr = flag[3]
|
||||||
|
yd = flag[4]
|
||||||
|
if xl != "0":
|
||||||
|
xl = "-" + str(float(xl)/100) + "%"
|
||||||
|
else:
|
||||||
|
xl = "0%"
|
||||||
|
if xr != "0":
|
||||||
|
xr = "-" + str(float(xr)/100) + "%"
|
||||||
|
else:
|
||||||
|
xr = "0%"
|
||||||
|
if yu != "0":
|
||||||
|
yu = "-" + str(float(yu)/100) + "%"
|
||||||
|
else:
|
||||||
|
yu = "0%"
|
||||||
|
if yd != "0":
|
||||||
|
yd = "-" + str(float(yd)/100) + "%"
|
||||||
|
else:
|
||||||
|
yd = "0%"
|
||||||
|
return xl, yu, xr, yd
|
||||||
|
return '0%', '0%', '0%', '0%'
|
||||||
|
|
||||||
|
|
||||||
def buildNCX(dstdir, title, chapters, chapterNames):
|
def buildNCX(dstdir, title, chapters, chapterNames):
|
||||||
options.uuid = str(uuid4())
|
options.uuid = str(uuid4())
|
||||||
ncxfile = os.path.join(dstdir, 'OEBPS', 'toc.ncx')
|
ncxfile = os.path.join(dstdir, 'OEBPS', 'toc.ncx')
|
||||||
@@ -331,10 +331,11 @@ def applyImgOptimization(img, opt, hqImage=None):
|
|||||||
|
|
||||||
|
|
||||||
def dirImgProcess(path):
|
def dirImgProcess(path):
|
||||||
global workerPool, workerOutput
|
global workerPool, workerOutput, theGreatIndex
|
||||||
workerPool = Pool()
|
workerPool = Pool()
|
||||||
workerOutput = []
|
workerOutput = []
|
||||||
work = []
|
work = []
|
||||||
|
theGreatIndex = {}
|
||||||
pagenumber = 0
|
pagenumber = 0
|
||||||
for (dirpath, dirnames, filenames) in os.walk(path):
|
for (dirpath, dirnames, filenames) in os.walk(path):
|
||||||
for afile in filenames:
|
for afile in filenames:
|
||||||
@@ -360,9 +361,15 @@ def dirImgProcess(path):
|
|||||||
|
|
||||||
|
|
||||||
def fileImgProcess_tick(output):
|
def fileImgProcess_tick(output):
|
||||||
if output:
|
if isinstance(output, str):
|
||||||
workerOutput.append(output)
|
workerOutput.append(output)
|
||||||
workerPool.terminate()
|
workerPool.terminate()
|
||||||
|
else:
|
||||||
|
for page in output:
|
||||||
|
if page is not None:
|
||||||
|
if sys.platform.startswith('win'):
|
||||||
|
page[0] = page[0].replace('/', '\\')
|
||||||
|
theGreatIndex[page[0]] = page[1]
|
||||||
if GUI:
|
if GUI:
|
||||||
GUI.progressBarTick.emit('tick')
|
GUI.progressBarTick.emit('tick')
|
||||||
if not GUI.conversionAlive:
|
if not GUI.conversionAlive:
|
||||||
@@ -374,6 +381,7 @@ def fileImgProcess(work):
|
|||||||
afile = work[0]
|
afile = work[0]
|
||||||
dirpath = work[1]
|
dirpath = work[1]
|
||||||
opt = work[2]
|
opt = work[2]
|
||||||
|
output = []
|
||||||
if opt.verbose:
|
if opt.verbose:
|
||||||
print("Optimizing " + afile + " for " + opt.profile)
|
print("Optimizing " + afile + " for " + opt.profile)
|
||||||
else:
|
else:
|
||||||
@@ -392,26 +400,21 @@ def fileImgProcess(work):
|
|||||||
print("Splitted " + afile)
|
print("Splitted " + afile)
|
||||||
img0 = image.ComicPage(split[0], opt.profileData)
|
img0 = image.ComicPage(split[0], opt.profileData)
|
||||||
applyImgOptimization(img0, opt)
|
applyImgOptimization(img0, opt)
|
||||||
img0.saveToDir(dirpath, opt.forcepng, opt.forcecolor)
|
output.append(img0.saveToDir(dirpath, opt.forcepng, opt.forcecolor))
|
||||||
img1 = image.ComicPage(split[1], opt.profileData)
|
img1 = image.ComicPage(split[1], opt.profileData)
|
||||||
applyImgOptimization(img1, opt)
|
applyImgOptimization(img1, opt)
|
||||||
img1.saveToDir(dirpath, opt.forcepng, opt.forcecolor)
|
output.append(img1.saveToDir(dirpath, opt.forcepng, opt.forcecolor))
|
||||||
if wipe:
|
|
||||||
os.remove(os.path.join(dirpath, img0.filename))
|
|
||||||
os.remove(os.path.join(dirpath, img1.filename))
|
|
||||||
if opt.quality == 2:
|
if opt.quality == 2:
|
||||||
img0b = image.ComicPage(split[0], opt.profileData, img0.fill)
|
img0b = image.ComicPage(split[0], opt.profileData, img0.fill)
|
||||||
applyImgOptimization(img0b, opt, img0)
|
applyImgOptimization(img0b, opt, img0)
|
||||||
img0b.saveToDir(dirpath, opt.forcepng, opt.forcecolor)
|
output.append(img0b.saveToDir(dirpath, opt.forcepng, opt.forcecolor))
|
||||||
img1b = image.ComicPage(split[1], opt.profileData, img1.fill)
|
img1b = image.ComicPage(split[1], opt.profileData, img1.fill)
|
||||||
applyImgOptimization(img1b, opt, img1)
|
applyImgOptimization(img1b, opt, img1)
|
||||||
img1b.saveToDir(dirpath, opt.forcepng, opt.forcecolor)
|
output.append(img1b.saveToDir(dirpath, opt.forcepng, opt.forcecolor))
|
||||||
os.remove(os.path.join(dirpath, img0b.filename))
|
|
||||||
os.remove(os.path.join(dirpath, img1b.filename))
|
|
||||||
os.remove(img.origFileName)
|
os.remove(img.origFileName)
|
||||||
else:
|
else:
|
||||||
applyImgOptimization(img, opt)
|
applyImgOptimization(img, opt)
|
||||||
img.saveToDir(dirpath, opt.forcepng, opt.forcecolor)
|
output.append(img.saveToDir(dirpath, opt.forcepng, opt.forcecolor))
|
||||||
if wipe:
|
if wipe:
|
||||||
os.remove(os.path.join(dirpath, img.filename))
|
os.remove(os.path.join(dirpath, img.filename))
|
||||||
if opt.quality == 2:
|
if opt.quality == 2:
|
||||||
@@ -420,8 +423,9 @@ def fileImgProcess(work):
|
|||||||
img2.image = img2.image.rotate(90)
|
img2.image = img2.image.rotate(90)
|
||||||
img2.rotated = True
|
img2.rotated = True
|
||||||
applyImgOptimization(img2, opt, img)
|
applyImgOptimization(img2, opt, img)
|
||||||
img2.saveToDir(dirpath, opt.forcepng, opt.forcecolor)
|
output.append(img2.saveToDir(dirpath, opt.forcepng, opt.forcecolor))
|
||||||
os.remove(os.path.join(dirpath, img2.filename))
|
os.remove(os.path.join(dirpath, img2.filename))
|
||||||
|
return output
|
||||||
except Exception:
|
except Exception:
|
||||||
return str(sys.exc_info()[1])
|
return str(sys.exc_info()[1])
|
||||||
|
|
||||||
@@ -546,8 +550,9 @@ def genEpubStruct(path, chapterNames):
|
|||||||
chapter = False
|
chapter = False
|
||||||
for afile in filenames:
|
for afile in filenames:
|
||||||
filename = getImageFileName(afile)
|
filename = getImageFileName(afile)
|
||||||
if filename is not None and not "-kcchq" in filename[0]:
|
if filename is not None and not ('-kcc-hq' in filename[0] or '-kcc-a-hq' in filename[0]
|
||||||
filelist.append(buildHTML(dirpath, afile))
|
or '-kcc-b-hq' in filename[0]):
|
||||||
|
filelist.append(buildHTML(dirpath, afile, os.path.join(dirpath, afile)))
|
||||||
if not chapter:
|
if not chapter:
|
||||||
chapterlist.append((dirpath.replace('Images', 'Text'), filelist[-1][1]))
|
chapterlist.append((dirpath.replace('Images', 'Text'), filelist[-1][1]))
|
||||||
chapter = True
|
chapter = True
|
||||||
@@ -674,6 +679,8 @@ def sanitizeTree(filetree):
|
|||||||
!= slugified.upper():
|
!= slugified.upper():
|
||||||
slugified += "A"
|
slugified += "A"
|
||||||
os.rename(os.path.join(root, name), os.path.join(root, slugified + splitname[1]))
|
os.rename(os.path.join(root, name), os.path.join(root, slugified + splitname[1]))
|
||||||
|
theGreatIndex[os.path.join(root, slugified + splitname[1])] = theGreatIndex[os.path.join(root, name)]
|
||||||
|
del theGreatIndex[os.path.join(root, name)]
|
||||||
for name in dirs:
|
for name in dirs:
|
||||||
if name.startswith('.'):
|
if name.startswith('.'):
|
||||||
os.remove(os.path.join(root, name))
|
os.remove(os.path.join(root, name))
|
||||||
|
|||||||
41
kcc/image.py
41
kcc/image.py
@@ -112,6 +112,7 @@ class ComicPage:
|
|||||||
self.noVPV = None
|
self.noVPV = None
|
||||||
self.noPV = None
|
self.noPV = None
|
||||||
self.purge = False
|
self.purge = False
|
||||||
|
self.hq = False
|
||||||
if fill:
|
if fill:
|
||||||
self.fill = fill
|
self.fill = fill
|
||||||
else:
|
else:
|
||||||
@@ -119,30 +120,37 @@ class ComicPage:
|
|||||||
|
|
||||||
def saveToDir(self, targetdir, forcepng, color):
|
def saveToDir(self, targetdir, forcepng, color):
|
||||||
try:
|
try:
|
||||||
suffix = ""
|
flags = []
|
||||||
|
filename = os.path.join(targetdir, os.path.splitext(self.filename)[0])
|
||||||
|
if not filename.endswith('-KCC-A') and not filename.endswith('-KCC-B'):
|
||||||
|
filename += '-KCC'
|
||||||
if not color and not forcepng:
|
if not color and not forcepng:
|
||||||
self.image = self.image.convert('L')
|
self.image = self.image.convert('L')
|
||||||
if self.rotated:
|
if self.rotated:
|
||||||
suffix += "-kccrot"
|
flags.append('Rotated')
|
||||||
else:
|
if self.hq:
|
||||||
suffix += "-kcchq"
|
flags.append('HighQuality')
|
||||||
|
filename += '-HQ'
|
||||||
if self.noPV:
|
if self.noPV:
|
||||||
suffix += "-kccnpv"
|
flags.append('NoPanelView')
|
||||||
else:
|
else:
|
||||||
if self.noHPV:
|
if self.noHPV:
|
||||||
suffix += "-kccnh"
|
flags.append('NoHorizontalPanelView')
|
||||||
if self.noVPV:
|
if self.noVPV:
|
||||||
suffix += "-kccnv"
|
flags.append('NoVerticalPanelView')
|
||||||
if self.border:
|
if self.border:
|
||||||
suffix += "-kccxl" + str(self.border[0]) + "-kccyu" + str(self.border[1]) + "-kccxr" +\
|
flags.append("Margins-" + str(self.border[0]) + "-" + str(self.border[1]) + "-"
|
||||||
str(self.border[2]) + "-kccyd" + str(self.border[3])
|
+ str(self.border[2]) + "-" + str(self.border[3]))
|
||||||
if not self.purge:
|
if not self.purge:
|
||||||
if forcepng:
|
if forcepng:
|
||||||
self.image.save(os.path.join(targetdir, os.path.splitext(self.filename)[0] + suffix + ".png"),
|
filename += ".png"
|
||||||
"PNG", optimize=1)
|
self.image.save(filename, "PNG", optimize=1)
|
||||||
else:
|
else:
|
||||||
self.image.save(os.path.join(targetdir, os.path.splitext(self.filename)[0] + suffix + ".jpg"),
|
filename += ".jpg"
|
||||||
"JPEG", optimize=1)
|
self.image.save(filename, "JPEG", optimize=1)
|
||||||
|
return [filename, flags]
|
||||||
|
else:
|
||||||
|
return None
|
||||||
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))
|
||||||
|
|
||||||
@@ -211,7 +219,10 @@ class ComicPage:
|
|||||||
# Set target size
|
# Set target size
|
||||||
if qualityMode == 0:
|
if qualityMode == 0:
|
||||||
size = (self.size[0], self.size[1])
|
size = (self.size[0], self.size[1])
|
||||||
|
elif qualityMode == 1:
|
||||||
|
size = (self.panelviewsize[0], self.panelviewsize[1])
|
||||||
else:
|
else:
|
||||||
|
self.hq = True
|
||||||
size = (self.panelviewsize[0], self.panelviewsize[1])
|
size = (self.panelviewsize[0], self.panelviewsize[1])
|
||||||
# If image is small and HQ mode is on we have to force upscaling. Otherwise non-zoomed image will be distorted
|
# If image is small and HQ mode is on we have to force upscaling. Otherwise non-zoomed image will be distorted
|
||||||
if self.image.size[0] <= size[0] and self.image.size[1] <= size[1] and qualityMode == 1 and not stretch:
|
if self.image.size[0] <= size[0] and self.image.size[1] <= size[1] and qualityMode == 1 and not stretch:
|
||||||
@@ -271,8 +282,8 @@ class ComicPage:
|
|||||||
leftbox = (0, 0, width, int(height / 2))
|
leftbox = (0, 0, width, int(height / 2))
|
||||||
rightbox = (0, int(height / 2), width, height)
|
rightbox = (0, int(height / 2), width, height)
|
||||||
filename = os.path.splitext(self.filename)
|
filename = os.path.splitext(self.filename)
|
||||||
fileone = targetdir + '/' + filename[0] + '-kcca' + filename[1]
|
fileone = targetdir + '/' + filename[0] + '-KCC-A' + filename[1]
|
||||||
filetwo = targetdir + '/' + filename[0] + '-kccb' + filename[1]
|
filetwo = targetdir + '/' + filename[0] + '-KCC-B' + filename[1]
|
||||||
try:
|
try:
|
||||||
if righttoleft:
|
if righttoleft:
|
||||||
pageone = self.image.crop(rightbox)
|
pageone = self.image.crop(rightbox)
|
||||||
|
|||||||
Reference in New Issue
Block a user