From 1608f10fbdbae77199551d40d89e623c8aa9fbd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gab=C3=A8s=20Jean?= Date: Mon, 5 Oct 2015 21:30:28 +0200 Subject: [PATCH] Add: do not split images that do not need to Some pictures (like the front in a scan) can be not double pages, so for theses pictures, try to detect if width> height, and if not remove split flags for this specific source picture. --- mangle/convert.py | 16 +++++++++++++--- mangle/image.py | 12 ++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/mangle/convert.py b/mangle/convert.py index d9bdf8f..326f465 100644 --- a/mangle/convert.py +++ b/mangle/convert.py @@ -121,8 +121,18 @@ class DialogConvert(QtGui.QProgressDialog): archive = self.archive pdf = self.pdf - # For right page (if requested) - if(self.book.imageFlags & ImageFlags.Split): + + # Maybe the user ask for a split, but the picture is not a large one, so skip + # it but only for this picture + if (flags & ImageFlags.Split) or (flags & ImageFlags.SplitInverse): + if not image.isSplitable(source): + # remove split flags + splitFlags= [ImageFlags.Split, ImageFlags.SplitInverse, ImageFlags.SplitRight, ImageFlags.SplitLeft] + for f in splitFlags: + flags &= ~f + + # For right page (if requested in options and need for this image) + if(flags & ImageFlags.Split): # New path based on modified index target = os.path.join(self.bookPath, '%05d.png' % (index * 2 + 0)) self.convertAndSave(source, target, device, flags ^ ImageFlags.Split | ImageFlags.SplitRight, archive, pdf) @@ -130,7 +140,7 @@ class DialogConvert(QtGui.QProgressDialog): target = os.path.join(self.bookPath, '%05d.png' % (index * 2 + 1)) # For right page (if requested), but in inverted mode - if(self.book.imageFlags & ImageFlags.SplitInverse): + if(flags & ImageFlags.SplitInverse): # New path based on modified index target = os.path.join(self.bookPath, '%05d.png' % (index * 2 + 0)) self.convertAndSave(source, target, device, flags ^ ImageFlags.SplitInverse | ImageFlags.SplitLeft, archive, pdf) diff --git a/mangle/image.py b/mangle/image.py index 15d1992..67358e1 100644 --- a/mangle/image.py +++ b/mangle/image.py @@ -221,6 +221,18 @@ def saveImage(image, target): raise RuntimeError('Cannot write image file %s' % target) +# Look if the image is more width than hight, if not, means +# it's should not be split (like the front page of a manga, +# when all the inner pages are double) +def isSplitable(source): + image = loadImage(source) + try: + widthImg, heightImg = image.size + return widthImg > heightImg + except IOError: + raise RuntimeError('Cannot read image file %s' % source) + + def convertImage(source, target, device, flags): try: size, palette = KindleData.Profiles[device]