From 3e007965b29505ca6139d84bd376bc652ac68f2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Date: Mon, 27 May 2013 15:21:16 +0200 Subject: [PATCH] Fixed panel order for horizontal pages when --rotate is enabled --- README.md | 5 +++-- kcc/comic2ebook.py | 16 ++++++++++------ kcc/image.py | 12 ++++++++---- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 497a386..c5c3e69 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ The app relies and includes the following scripts/binaries: * Add rendition:layout and rendition:orientation ePub meta tags (supported by new kindlegen 2.8) * Fixed natural sorting for files (#18) -####2.7: +####2.7 * Lots of GUI improvements (#27, #13) * Added gamma support within --gamma option (defaults to profile-specified gamma) (#26, #27) * Added --nodithering option to prevent dithering optimizations (#27) @@ -167,7 +167,7 @@ The app relies and includes the following scripts/binaries: * Added generic CSS file * Optimized archive extraction for zip/rar files (#40) -####2.9: +####2.9 * Added support for generating a plain CBZ (skipping all the EPUB/Mobi generation) (#45) * Prevent output file overwriting the source one: if a duplicate name is detected, append _kcc to the name * Rarfile library updated to 2.6 @@ -177,6 +177,7 @@ The app relies and includes the following scripts/binaries: ####2.10: * Kindle Fire support (color ePub/Mobi) * Panel View support for horizontal content +* Fixed panel order for horizontal pages when --rotate is enabled ## COPYRIGHT diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py index 36be9c0..68a22ce 100755 --- a/kcc/comic2ebook.py +++ b/kcc/comic2ebook.py @@ -40,6 +40,10 @@ import pdfjpgextract def buildHTML(path, imgfile): filename = getImageFileName(imgfile) if filename is not None: + if "_rotated" in str(filename): + rotate = True + else: + rotate = False htmlpath = '' postfix = '' backref = 1 @@ -70,7 +74,7 @@ def buildHTML(path, imgfile): imgfile, "\" class=\"singlePage\"/>\n" ]) if options.panelview: - if options.panelviewhorizontal: + if options.panelviewhorizontal or rotate: if options.righttoleft: f.writelines(["
\n", @@ -348,7 +352,7 @@ def dirImgProcess(path): split = None else: split = img.splitPage(dirpath, options.righttoleft, options.rotate) - if split is not None: + if split is not None and split is not "R": if options.verbose: print "Splitted " + afile if options.righttoleft: @@ -365,17 +369,17 @@ def dirImgProcess(path): facing = "left" img0 = image.ComicPage(split[0], options.profile) applyImgOptimization(img0, True, toRight1) - img0.saveToDir(dirpath, options.forcepng, options.forcecolor) + img0.saveToDir(dirpath, options.forcepng, options.forcecolor, split) img1 = image.ComicPage(split[1], options.profile) applyImgOptimization(img1, True, toRight2) - img1.saveToDir(dirpath, options.forcepng, options.forcecolor) + img1.saveToDir(dirpath, options.forcepng, options.forcecolor, split) else: if facing == "right": facing = "left" else: facing = "right" applyImgOptimization(img) - img.saveToDir(dirpath, options.forcepng, options.forcecolor) + img.saveToDir(dirpath, options.forcepng, options.forcecolor, split) def genEpubStruct(path): @@ -712,7 +716,7 @@ def checkOptions(): options.forcepng = False else: options.forcecolor = False - if options.panelviewhorizontal: + if options.panelviewhorizontal or options.rotate: options.panelview = True options.landscapemode = False diff --git a/kcc/image.py b/kcc/image.py index 896058a..e4fb7b2 100755 --- a/kcc/image.py +++ b/kcc/image.py @@ -119,16 +119,20 @@ class ComicPage: raise RuntimeError('Cannot read image file %s' % source) self.image = self.image.convert('RGB') - def saveToDir(self, targetdir, forcepng, color): + def saveToDir(self, targetdir, forcepng, color, sufix): filename = os.path.basename(self.origFileName) try: if not color: self.image = self.image.convert('L') # convert to grayscale + if sufix == "R": + sufix = "_rotated" + else: + sufix = "" os.remove(os.path.join(targetdir, filename)) if forcepng: - self.image.save(os.path.join(targetdir, os.path.splitext(filename)[0] + ".png"), "PNG") + self.image.save(os.path.join(targetdir, os.path.splitext(filename)[0] + sufix + ".png"), "PNG") else: - self.image.save(os.path.join(targetdir, os.path.splitext(filename)[0] + ".jpg"), "JPEG") + self.image.save(os.path.join(targetdir, os.path.splitext(filename)[0] + sufix + ".jpg"), "JPEG") except IOError as e: raise RuntimeError('Cannot write image in directory %s: %s' % (targetdir, e)) @@ -202,7 +206,7 @@ class ComicPage: if (width > height) != (dstwidth > dstheight): if rotate: self.image = self.image.rotate(90) - return None + return "R" else: if width > height: # source is landscape, so split by the width