1
0
mirror of https://github.com/ciromattia/kcc synced 2026-01-28 07:57:41 +00:00

Fixed a serious bug on resizing when img ratio was bigger than device one

This commit is contained in:
Ciro Mattia Gonano
2013-01-18 11:54:34 +01:00
parent f231e9112a
commit 9ee851d04b
3 changed files with 13 additions and 4 deletions

View File

@@ -89,6 +89,7 @@ and installed in `/usr/local/bin/`
Reworked options system (call with -h option to get the inline help)
- 1.40 - Added some options for controlling image optimization
Further optimization (ImageOps, page numbering cut, autocontrast)
- 1.41 - Fixed a serious bug on resizing when img ratio was bigger than device one
- 2.00 - GUI! AppleScript is gone and Tk is used to provide cross-platform GUI support.
## TODO

View File

@@ -26,6 +26,9 @@
# WARNING: PIL is required for all image mangling!
# 1.30 - Fixed an issue in OPF generation for device resolution
# Reworked options system (call with -h option to get the inline help)
# 1.40 - Added some options for controlling image optimization
# Further optimization (ImageOps, page numbering cut, autocontrast)
# 1.41 - Fixed a serious bug on resizing when img ratio was bigger than device one
#
# Todo:
# - Add gracefully exit for CBR if no rarfile.py and no unrar
@@ -180,17 +183,21 @@ def main(argv=None):
raise
filelist = []
if options.imgproc:
print "Processing images..."
try:
if options.verbose:
print "Splitting double pages..."
for file in os.listdir(dir):
if getImageFileName(file) is not None:
print ".",
img = image.ComicPage(dir+'/'+file, options.profile)
img.splitPage(dir, options.righttoleft)
for file in os.listdir(dir):
if getImageFileName(file) is not None:
if options.verbose:
print "Optimizing " + file + " for " + options.profile
else:
print ".",
img = image.ComicPage(dir+'/'+file, options.profile)
img.optimizeImage()
img.cropWhiteSpace(10.0)
@@ -202,6 +209,7 @@ def main(argv=None):
except ImportError:
print "Could not load PIL, not optimizing image"
print "Creating ePub structure..."
for file in os.listdir(dir):
if getImageFileName(file) is not None and isInFilelist(file,filelist) == False:
# put credits at the end
@@ -215,7 +223,7 @@ def main(argv=None):
options.title = os.path.basename(dir)
NCXbuilder(dir,options.title)
# ensure we're sorting files alphabetically
filelist = sorted(filelist, key=lambda name: name[0])
filelist = sorted(filelist, key=lambda name: name[0].lower())
OPFBuilder(options.profile,dir,options.title,filelist)

View File

@@ -96,7 +96,7 @@ class ComicPage:
def saveToDir(self,targetdir):
filename = os.path.basename(self.origFileName)
print "Saving to " + targetdir + '/' + filename
#print "Saving to " + targetdir + '/' + filename
try:
self.image = self.image.convert('L') # convert to grayscale
self.image.save(targetdir + '/' + filename,"JPEG")
@@ -133,7 +133,7 @@ class ComicPage:
newImage.paste(self.image, (diff / 2, 0, diff / 2 + self.image.size[0], self.image.size[1]))
self.image = newImage
elif (float(self.image.size[0]) / float(self.image.size[1])) > ratioDev:
diff = int(self.image.size[0] * ratioDev) - self.image.size[1]
diff = int(self.image.size[0] / ratioDev) - self.image.size[1]
newImage = Image.new('RGB', (self.image.size[0], self.image.size[1] + diff), (255,255,255))
newImage.paste(self.image, (0, diff / 2, self.image.size[0], diff / 2 + self.image.size[1]))
self.image = newImage
@@ -143,7 +143,7 @@ class ComicPage:
def splitPage(self, targetdir, righttoleft=False):
width, height = self.image.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
if (width > height) != (dstwidth > dstheight):
if width > height: