mirror of
https://github.com/ciromattia/kcc
synced 2025-12-12 17:26:23 +00:00
Added option to rotate images instead spliting.
This commit is contained in:
10
.gitignore
vendored
10
.gitignore
vendored
@@ -1,5 +1,5 @@
|
|||||||
/*.pyc
|
*.pyc
|
||||||
/*.cbz
|
*.cbz
|
||||||
/*.cbr
|
*.cbr
|
||||||
/.idea
|
.idea
|
||||||
/build
|
build
|
||||||
@@ -227,7 +227,7 @@ def dirImgProcess(path):
|
|||||||
else:
|
else:
|
||||||
print ".",
|
print ".",
|
||||||
img = image.ComicPage(os.path.join(dirpath, afile), options.profile)
|
img = image.ComicPage(os.path.join(dirpath, afile), options.profile)
|
||||||
split = img.splitPage(dirpath, options.righttoleft)
|
split = img.splitPage(dirpath, options.righttoleft, options.rotate)
|
||||||
if split is not None:
|
if split is not None:
|
||||||
if options.verbose:
|
if options.verbose:
|
||||||
print "Splitted " + afile
|
print "Splitted " + afile
|
||||||
@@ -333,6 +333,8 @@ def main(argv=None):
|
|||||||
+ "is not like the device's one [default=False]")
|
+ "is not like the device's one [default=False]")
|
||||||
parser.add_option("--no-cut-page-numbers", action="store_false", dest="cutpagenumbers", default=True,
|
parser.add_option("--no-cut-page-numbers", action="store_false", dest="cutpagenumbers", default=True,
|
||||||
help="Do not try to cut page numbering on images [default=True]")
|
help="Do not try to cut page numbering on images [default=True]")
|
||||||
|
parser.add_option("--rotate", action="store_true", dest="rotate", default=False,
|
||||||
|
help="Disable page spliting. Instead rotate images [default=False]")
|
||||||
options, args = parser.parse_args(argv)
|
options, args = parser.parse_args(argv)
|
||||||
if len(args) != 1:
|
if len(args) != 1:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
|||||||
54
kcc/image.py
54
kcc/image.py
@@ -159,36 +159,40 @@ class ComicPage:
|
|||||||
self.image = ImageOps.fit(self.image, self.size, method=method, centering=(0.5, 0.5))
|
self.image = ImageOps.fit(self.image, self.size, method=method, centering=(0.5, 0.5))
|
||||||
return self.image
|
return self.image
|
||||||
|
|
||||||
def splitPage(self, targetdir, righttoleft=False):
|
def splitPage(self, targetdir, righttoleft=False, rotate=False):
|
||||||
width, height = self.image.size
|
width, height = self.image.size
|
||||||
dstwidth, dstheight = self.size
|
dstwidth, dstheight = self.size
|
||||||
#print "Image is %d x %d" % (width,height)
|
#print "Image is %d x %d" % (width,height)
|
||||||
# only split if origin is not oriented the same as target
|
# only split if origin is not oriented the same as target
|
||||||
if (width > height) != (dstwidth > dstheight):
|
if (width > height) != (dstwidth > dstheight):
|
||||||
if width > height:
|
if rotate:
|
||||||
# source is landscape, so split by the width
|
self.image = self.image.rotate(90)
|
||||||
leftbox = (0, 0, width / 2, height)
|
return None
|
||||||
rightbox = (width / 2, 0, width, height)
|
else:
|
||||||
else:
|
if width > height:
|
||||||
# source is portrait and target is landscape, so split by the height
|
# source is landscape, so split by the width
|
||||||
leftbox = (0, 0, width, height / 2)
|
leftbox = (0, 0, width / 2, height)
|
||||||
rightbox = (0, height / 2, width, height)
|
rightbox = (width / 2, 0, width, height)
|
||||||
filename = os.path.splitext(os.path.basename(self.origFileName))
|
else:
|
||||||
fileone = targetdir + '/' + filename[0] + '-1' + filename[1]
|
# source is portrait and target is landscape, so split by the height
|
||||||
filetwo = targetdir + '/' + filename[0] + '-2' + filename[1]
|
leftbox = (0, 0, width, height / 2)
|
||||||
try:
|
rightbox = (0, height / 2, width, height)
|
||||||
if righttoleft:
|
filename = os.path.splitext(os.path.basename(self.origFileName))
|
||||||
pageone = self.image.crop(rightbox)
|
fileone = targetdir + '/' + filename[0] + '-1' + filename[1]
|
||||||
pagetwo = self.image.crop(leftbox)
|
filetwo = targetdir + '/' + filename[0] + '-2' + filename[1]
|
||||||
else:
|
try:
|
||||||
pageone = self.image.crop(leftbox)
|
if righttoleft:
|
||||||
pagetwo = self.image.crop(rightbox)
|
pageone = self.image.crop(rightbox)
|
||||||
pageone.save(fileone)
|
pagetwo = self.image.crop(leftbox)
|
||||||
pagetwo.save(filetwo)
|
else:
|
||||||
os.remove(self.origFileName)
|
pageone = self.image.crop(leftbox)
|
||||||
except IOError as e:
|
pagetwo = self.image.crop(rightbox)
|
||||||
raise RuntimeError('Cannot write image in directory %s: %s' % (targetdir, e))
|
pageone.save(fileone)
|
||||||
return fileone, filetwo
|
pagetwo.save(filetwo)
|
||||||
|
os.remove(self.origFileName)
|
||||||
|
except IOError as e:
|
||||||
|
raise RuntimeError('Cannot write image in directory %s: %s' % (targetdir, e))
|
||||||
|
return fileone, filetwo
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user