mirror of
https://github.com/ciromattia/kcc
synced 2025-12-13 01:36:27 +00:00
Pillow update
This commit is contained in:
@@ -40,10 +40,10 @@ except ImportError:
|
||||
try:
|
||||
# noinspection PyUnresolvedReferences
|
||||
import PIL
|
||||
if tuple(map(int, ('2.5.0'.split(".")))) > tuple(map(int, (PIL.PILLOW_VERSION.split(".")))):
|
||||
missing.append('Pillow 2.5.0+')
|
||||
if tuple(map(int, ('2.7.0'.split(".")))) > tuple(map(int, (PIL.PILLOW_VERSION.split(".")))):
|
||||
missing.append('Pillow 2.7.0+')
|
||||
except ImportError:
|
||||
missing.append('Pillow 2.5.0+')
|
||||
missing.append('Pillow 2.7.0+')
|
||||
try:
|
||||
# noinspection PyUnresolvedReferences
|
||||
import slugify
|
||||
|
||||
@@ -33,10 +33,10 @@ missing = []
|
||||
try:
|
||||
# noinspection PyUnresolvedReferences
|
||||
import PIL
|
||||
if tuple(map(int, ('2.5.0'.split(".")))) > tuple(map(int, (PIL.PILLOW_VERSION.split(".")))):
|
||||
missing.append('Pillow 2.5.0+')
|
||||
if tuple(map(int, ('2.7.0'.split(".")))) > tuple(map(int, (PIL.PILLOW_VERSION.split(".")))):
|
||||
missing.append('Pillow 2.7.0+')
|
||||
except ImportError:
|
||||
missing.append('Pillow 2.5.0+')
|
||||
missing.append('Pillow 2.7.0+')
|
||||
if len(missing) > 0:
|
||||
try:
|
||||
# noinspection PyUnresolvedReferences
|
||||
|
||||
6
kcc.py
6
kcc.py
@@ -68,10 +68,10 @@ except ImportError:
|
||||
try:
|
||||
# noinspection PyUnresolvedReferences
|
||||
import PIL
|
||||
if tuple(map(int, ('2.5.0'.split(".")))) > tuple(map(int, (PIL.PILLOW_VERSION.split(".")))):
|
||||
missing.append('Pillow 2.5.0+')
|
||||
if tuple(map(int, ('2.7.0'.split(".")))) > tuple(map(int, (PIL.PILLOW_VERSION.split(".")))):
|
||||
missing.append('Pillow 2.7.0+')
|
||||
except ImportError:
|
||||
missing.append('Pillow 2.5.0+')
|
||||
missing.append('Pillow 2.7.0+')
|
||||
try:
|
||||
# noinspection PyUnresolvedReferences
|
||||
import slugify
|
||||
|
||||
@@ -552,7 +552,7 @@ def imgFileProcessing(work):
|
||||
if opt.quality == 2:
|
||||
img2 = image.ComicPage(os.path.join(dirpath, afile), opt.profileData, img.fill)
|
||||
if img.rotated:
|
||||
img2.image = img2.image.rotate(90)
|
||||
img2.image = img2.image.rotate(90, Image.BICUBIC, True)
|
||||
img2.rotated = True
|
||||
imgOptimization(img2, opt, img)
|
||||
output.append(img2.saveToDir(dirpath, opt.forcepng, opt.forcecolor))
|
||||
|
||||
@@ -77,7 +77,7 @@ def mergeDirectory(work):
|
||||
y += img.size[1]
|
||||
os.remove(i)
|
||||
savePath = os.path.split(imagesClear[0])
|
||||
result.save(os.path.join(savePath[0], os.path.splitext(savePath[1])[0] + '.png'), 'PNG')
|
||||
result.save(os.path.join(savePath[0], os.path.splitext(savePath[1])[0] + '.png'), 'PNG', optimize=1)
|
||||
except Exception:
|
||||
return str(sys.exc_info()[1])
|
||||
|
||||
@@ -165,7 +165,7 @@ def splitImage(work):
|
||||
panels.append(panel)
|
||||
if opt.debug:
|
||||
# noinspection PyUnboundLocalVariable
|
||||
debugImage.save(os.path.join(path, fileExpanded[0] + '-debug.png'), 'PNG')
|
||||
debugImage.save(os.path.join(path, fileExpanded[0] + '-debug.png'), 'PNG', optimize=1)
|
||||
|
||||
# Create virtual pages
|
||||
pages = []
|
||||
@@ -200,7 +200,7 @@ def splitImage(work):
|
||||
newPage.paste(panelImg, (0, targetHeight))
|
||||
targetHeight += panels[panel][2]
|
||||
newPage.save(os.path.join(path, fileExpanded[0] + '-' +
|
||||
str(pageNumber) + '.png'), 'PNG')
|
||||
str(pageNumber) + '.png'), 'PNG', optimize=1)
|
||||
pageNumber += 1
|
||||
os.remove(filePath)
|
||||
except Exception:
|
||||
|
||||
32
kcc/image.py
32
kcc/image.py
@@ -144,14 +144,14 @@ class ComicPage:
|
||||
if self.noVPV:
|
||||
flags.append('NoVerticalPanelView')
|
||||
if self.border:
|
||||
flags.append("Margins-" + str(self.border[0]) + "-" + str(self.border[1]) + "-"
|
||||
+ str(self.border[2]) + "-" + str(self.border[3]))
|
||||
flags.append('Margins-' + str(self.border[0]) + '-' + str(self.border[1]) + '-'
|
||||
+ str(self.border[2]) + '-' + str(self.border[3]))
|
||||
if forcepng:
|
||||
filename += ".png"
|
||||
self.image.save(filename, "PNG", optimize=1)
|
||||
filename += '.png'
|
||||
self.image.save(filename, 'PNG', optimize=1)
|
||||
else:
|
||||
filename += ".jpg"
|
||||
self.image.save(filename, "JPEG", optimize=1)
|
||||
filename += '.jpg'
|
||||
self.image.save(filename, 'JPEG', optimize=1, quality=80)
|
||||
return [md5Checksum(filename), flags]
|
||||
else:
|
||||
return None
|
||||
@@ -243,7 +243,7 @@ class ComicPage:
|
||||
if self.image.size[0] <= size[0] and self.image.size[1] <= size[1]:
|
||||
method = Image.BICUBIC
|
||||
else:
|
||||
method = Image.ANTIALIAS
|
||||
method = Image.LANCZOS
|
||||
self.image = self.image.resize(size, method)
|
||||
return self.image
|
||||
# If image is smaller than target resolution and upscale is off - Just expand it by adding margins
|
||||
@@ -269,7 +269,7 @@ class ComicPage:
|
||||
if self.image.size[0] <= size[0] and self.image.size[1] <= size[1]:
|
||||
method = Image.BICUBIC
|
||||
else:
|
||||
method = Image.ANTIALIAS
|
||||
method = Image.LANCZOS
|
||||
self.image = ImageOps.fit(self.image, size, method=method, centering=(0.5, 0.5))
|
||||
return self.image
|
||||
|
||||
@@ -279,7 +279,7 @@ class ComicPage:
|
||||
# Only split if origin is not oriented the same as target
|
||||
if (width > height) != (dstwidth > dstheight):
|
||||
if rotate:
|
||||
self.image = self.image.rotate(90)
|
||||
self.image = self.image.rotate(90, Image.BICUBIC, True)
|
||||
self.rotated = True
|
||||
return None
|
||||
else:
|
||||
@@ -292,9 +292,9 @@ class ComicPage:
|
||||
# Source is portrait and target is landscape, so split by the height
|
||||
leftbox = (0, 0, width, int(height / 2))
|
||||
rightbox = (0, int(height / 2), width, height)
|
||||
filename = os.path.splitext(self.filename)
|
||||
fileone = targetdir + '/' + filename[0] + '-A' + filename[1]
|
||||
filetwo = targetdir + '/' + filename[0] + '-B' + filename[1]
|
||||
filename = os.path.splitext(self.filename)[0]
|
||||
fileone = targetdir + '/' + filename + '-AAA.png'
|
||||
filetwo = targetdir + '/' + filename + '-BBB.png'
|
||||
try:
|
||||
if righttoleft:
|
||||
pageone = self.image.crop(rightbox)
|
||||
@@ -302,8 +302,8 @@ class ComicPage:
|
||||
else:
|
||||
pageone = self.image.crop(leftbox)
|
||||
pagetwo = self.image.crop(rightbox)
|
||||
pageone.save(fileone)
|
||||
pagetwo.save(filetwo)
|
||||
pageone.save(fileone, 'PNG', optimize=1)
|
||||
pagetwo.save(filetwo, 'PNG', optimize=1)
|
||||
except IOError as e:
|
||||
raise RuntimeError('Cannot write image in directory %s: %s' % (targetdir, e))
|
||||
return fileone, filetwo
|
||||
@@ -498,7 +498,7 @@ class Cover:
|
||||
|
||||
def processExternal(self):
|
||||
self.image = self.image.convert('RGB')
|
||||
self.image.thumbnail(self.options.profileData[1], Image.ANTIALIAS)
|
||||
self.image.thumbnail(self.options.profileData[1], Image.LANCZOS)
|
||||
self.save(True)
|
||||
|
||||
def trim(self):
|
||||
@@ -520,6 +520,6 @@ class Cover:
|
||||
if os.path.splitext(source)[1].lower() == '.png':
|
||||
self.image.save(self.target, "PNG", optimize=1)
|
||||
else:
|
||||
self.image.save(self.target, "JPEG", optimize=1)
|
||||
self.image.save(self.target, "JPEG", optimize=1, quality=80)
|
||||
except IOError:
|
||||
raise RuntimeError('Failed to save cover')
|
||||
|
||||
@@ -25,17 +25,11 @@ from hashlib import md5
|
||||
|
||||
|
||||
def getImageFileName(imgfile):
|
||||
filename = os.path.splitext(imgfile)
|
||||
if filename[0].startswith('.') or\
|
||||
(filename[1].lower() != '.png' and
|
||||
filename[1].lower() != '.jpg' and
|
||||
filename[1].lower() != '.gif' and
|
||||
filename[1].lower() != '.tif' and
|
||||
filename[1].lower() != '.tiff' and
|
||||
filename[1].lower() != '.bmp' and
|
||||
filename[1].lower() != '.jpeg'):
|
||||
name, ext = os.path.splitext(imgfile)
|
||||
ext = ext.lower()
|
||||
if name.startswith('.') or (ext != '.png' and ext != '.jpg' and ext != '.jpeg' and ext != '.gif'):
|
||||
return None
|
||||
return filename
|
||||
return [name, ext]
|
||||
|
||||
|
||||
def walkLevel(some_dir, level=1):
|
||||
|
||||
Reference in New Issue
Block a user