1
0
mirror of https://github.com/ciromattia/kcc synced 2026-01-27 23:47:41 +00:00

Landscape mode support - Image part. Not perfect.

New resizeImage function to properly display splitted pages in landscape
mode.
Enabling upscaling or stretching might result with not correct display
of splitted pages in landscape mode.
This commit is contained in:
Paweł Jastrzębski
2013-03-04 15:22:00 +01:00
parent 8d5ccf5d27
commit 7275856549
2 changed files with 25 additions and 9 deletions

View File

@@ -248,12 +248,12 @@ def isInFilelist(filename, filelist):
return seen
def applyImgOptimization(img):
def applyImgOptimization(img, isSplit=False, toRight=False):
img.optimizeImage()
img.cropWhiteSpace(10.0)
if options.cutpagenumbers:
img.cutPageNumber()
img.resizeImage(options.upscale, options.stretch, options.black_borders)
img.resizeImage(options.upscale, options.stretch, options.black_borders, isSplit, toRight)
img.quantizeImage()
@@ -272,11 +272,17 @@ def dirImgProcess(path):
if split is not None:
if options.verbose:
print "Splitted " + afile
if options.righttoleft:
toRight1 = False;
toRight2 = True;
else:
toRight1 = True;
toRight2 = False;
img0 = image.ComicPage(split[0], options.profile)
applyImgOptimization(img0)
applyImgOptimization(img0, True, toRight1)
img0.saveToDir(dirpath)
img1 = image.ComicPage(split[1], options.profile)
applyImgOptimization(img1)
applyImgOptimization(img1, True, toRight2)
img1.saveToDir(dirpath)
else:
applyImgOptimization(img)

View File

@@ -129,7 +129,7 @@ class ComicPage:
palImg.putpalette(self.palette)
self.image = self.image.quantize(palette=palImg)
def resizeImage(self, upscale=False, stretch=False, black_borders=False):
def resizeImage(self, upscale=False, stretch=False, black_borders=False, isSplit=False, toRight=False):
method = Image.ANTIALIAS
if black_borders:
fill = 'black'
@@ -137,10 +137,20 @@ class ComicPage:
fill = 'white'
if self.image.size[0] <= self.size[0] and self.image.size[1] <= self.size[1]:
if not upscale:
# do not upscale but center image in a device-sized image
borderw = (self.size[0] - self.image.size[0]) / 2
borderh = (self.size[1] - self.image.size[1]) / 2
self.image = ImageOps.expand(self.image, border=(borderw, borderh), fill=fill)
if isSplit:
borderw = (self.size[0] - self.image.size[0])
borderh = (self.size[1] - self.image.size[1]) / 2
self.image = ImageOps.expand(self.image, border=(0, borderh), fill=fill)
tempImg = Image.new(self.image.mode, (self.image.size[0] + borderw, self.image.size[1]), fill)
if toRight:
tempImg.paste(self.image, (borderw, 0))
else:
tempImg.paste(self.image, (0, 0))
self.image = tempImg
else:
borderw = (self.size[0] - self.image.size[0]) / 2
borderh = (self.size[1] - self.image.size[1]) / 2
self.image = ImageOps.expand(self.image, border=(borderw, borderh), fill=fill)
return self.image
else:
method = Image.NEAREST