Changed to split right -> left
This commit is contained in:
parent
1b2c5308eb
commit
0491b4f713
@ -18,6 +18,7 @@ import os
|
||||
import shutil
|
||||
|
||||
from PyQt4 import QtGui, QtCore
|
||||
from image import ImageFlags
|
||||
|
||||
import cbz
|
||||
import image
|
||||
@ -68,6 +69,14 @@ class DialogConvert(QtGui.QProgressDialog):
|
||||
shutil.rmtree(self.bookPath)
|
||||
|
||||
|
||||
def convertAndSave(self, source, target, device, flags, archive, pdf):
|
||||
image.convertImage(source, target, device, flags)
|
||||
if archive is not None:
|
||||
archive.addFile(target)
|
||||
if pdf is not None:
|
||||
pdf.addImage(target)
|
||||
|
||||
|
||||
def onTimer(self):
|
||||
index = self.value()
|
||||
target = os.path.join(self.bookPath, '%05d.png' % index)
|
||||
@ -107,11 +116,26 @@ class DialogConvert(QtGui.QProgressDialog):
|
||||
|
||||
try:
|
||||
if self.book.overwrite or not os.path.isfile(target):
|
||||
image.convertImage(source, target, str(self.book.device), self.book.imageFlags)
|
||||
if self.archive is not None:
|
||||
self.archive.addFile(target)
|
||||
if self.pdf is not None:
|
||||
self.pdf.addImage(target)
|
||||
device = str(self.book.device)
|
||||
flags = self.book.imageFlags
|
||||
archive = self.archive
|
||||
pdf = self.pdf
|
||||
|
||||
# For right page (if requested)
|
||||
if(self.book.imageFlags & ImageFlags.Split):
|
||||
# Increment counter to accomodate for extra page
|
||||
index = index + 1
|
||||
target = os.path.join(self.bookPath, '%05d.png' % index)
|
||||
self.convertAndSave(source,
|
||||
target
|
||||
device,
|
||||
flags ^ ImageFlags.Split | ImageFlags.SplitRight,
|
||||
archive,
|
||||
pdf)
|
||||
|
||||
# Convert page
|
||||
self.convertAndSave(source, target, device, flags, archive, pdf)
|
||||
|
||||
except RuntimeError, error:
|
||||
result = QtGui.QMessageBox.critical(
|
||||
self,
|
||||
|
@ -179,28 +179,36 @@ def frameImage(image, foreground, background, size):
|
||||
return imageBg
|
||||
|
||||
|
||||
def loadImage(source):
|
||||
try:
|
||||
return Image.open(source)
|
||||
except IOError:
|
||||
raise RuntimeError('Cannot read image file %s' % source)
|
||||
|
||||
|
||||
def saveImage(image, target):
|
||||
try:
|
||||
image.save(target)
|
||||
except IOError:
|
||||
raise RuntimeError('Cannot write image file %s' % target)
|
||||
|
||||
|
||||
def convertImage(source, target, device, flags):
|
||||
try:
|
||||
size, palette = KindleData.Profiles[device]
|
||||
except KeyError:
|
||||
raise RuntimeError('Unexpected output device %s' % device)
|
||||
|
||||
try:
|
||||
image = Image.open(source)
|
||||
except IOError:
|
||||
raise RuntimeError('Cannot read image file %s' % source)
|
||||
# Load image from source path
|
||||
image = loadImage(source)
|
||||
# Format according to palette
|
||||
image = formatImage(image)
|
||||
if flags & ImageFlags.Orient:
|
||||
image = orientImage(image, size)
|
||||
# Apply flag transforms
|
||||
if flags & ImageFlags.SplitRight:
|
||||
image = splitRight(image)
|
||||
elif flags & ImageFlags.Split:
|
||||
if flags & ImageFlags.Split:
|
||||
image = splitLeft(image)
|
||||
# Recurse for right page
|
||||
fileName, fileExtension = os.path.splitext(target)
|
||||
newTarget = fileName + "r" + fileExtension
|
||||
print(newTarget)
|
||||
convertImage(source, newTarget, device, flags | ImageFlags.SplitRight)
|
||||
if flags & ImageFlags.Orient:
|
||||
image = orientImage(image, size)
|
||||
if flags & ImageFlags.Resize:
|
||||
image = resizeImage(image, size)
|
||||
if flags & ImageFlags.Stretch:
|
||||
@ -210,7 +218,4 @@ def convertImage(source, target, device, flags):
|
||||
if flags & ImageFlags.Quantize:
|
||||
image = quantizeImage(image, palette)
|
||||
|
||||
try:
|
||||
image.save(target)
|
||||
except IOError:
|
||||
raise RuntimeError('Cannot write image file %s' % target)
|
||||
saveImage(image, target)
|
||||
|
@ -162,7 +162,7 @@
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkboxSplit">
|
||||
<property name="text">
|
||||
<string>Split left and right pages</string>
|
||||
<string>Split images into two pages (right, left)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
Loading…
Reference in New Issue
Block a user