diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py index 3fe51e2..311a6a3 100755 --- a/kcc/comic2ebook.py +++ b/kcc/comic2ebook.py @@ -61,26 +61,48 @@ def buildHTML(path, imgfile): "", filename[0], "\n", "\n", "\n", - "\n", + "style.css\" type=\"text/css\" rel=\"stylesheet\"/>\n", "\n", - "\n", - "
\"",
\n", - #"
\n", - #"\n", - #"
\n", - #"
\n", - #"
\n", - #"
\n", - #"
\n", - #"\"",\n", - #"
\n", - "\n", - "" + "\n", + "
\n", + "
\"",
\n" ]) + if options.panelview: + if options.righttoleft: + f.writelines(["
\n", + "
\n", + "
\n", + "
\n" + ]) + else: + f.writelines(["
\n", + "
\n", + "
\n", + "
\n" + ]) + f.writelines(["
\"",
\n", + "
\"",
\n", + "
\"",
\n", + "
\"",
\n" + ]) + f.writelines(["
\n\n"]) f.close() return path, imgfile @@ -128,12 +150,12 @@ def buildNCX(dstdir, title, chapters): return -def buildOPF(profile, dstdir, title, filelist, cover=None, righttoleft=False): +def buildOPF(profile, dstdir, title, filelist, cover=None): opffile = os.path.join(dstdir, 'OEBPS', 'content.opf') # read the first file resolution - profilelabel, deviceres, palette, gamma = image.ProfileData.Profiles[profile] + profilelabel, deviceres, palette, gamma, panelviewsize = image.ProfileData.Profiles[profile] imgres = str(deviceres[0]) + "x" + str(deviceres[1]) - if righttoleft: + if options.righttoleft: writingmode = "horizontal-rl" facing = "right" facing1 = "right" @@ -159,16 +181,19 @@ def buildOPF(profile, dstdir, title, filelist, cover=None, righttoleft=False): "\n", "\n", "\n", - "\n", - "\n", - "\n", + "\n" + ]) + if options.landscapemode: + f.writelines(["\n", + "\n"]) + else: + f.writelines(["\n", + "\n"]) + f.writelines(["\n", "\n", "\n", - "\n", "\n\n\n" - ]) - # set cover + "media-type=\"application/x-dtbncx+xml\"/>\n"]) if cover is not None: filename = getImageFileName(cover.replace(os.path.join(dstdir, 'OEBPS'), '').lstrip('/').lstrip('\\\\')) if '.png' == filename[1]: @@ -191,36 +216,46 @@ def buildOPF(profile, dstdir, title, filelist, cover=None, righttoleft=False): mt = 'image/jpeg' f.write("\n") - if (options.profile == 'K4' or options.profile == 'KHD') and splitCount > 0: + if options.landscapemode and splitCount > 0: splitCountUsed = 1 while splitCountUsed <= splitCount: f.write("\n") splitCountUsed += 1 + f.write("\n") f.write("\n\n") splitCountUsed = 1 for entry in reflist: if entry.endswith("-1"): - if ((righttoleft and facing == 'left') or (not righttoleft and facing == 'right')) and \ - (options.profile == 'K4' or options.profile == 'KHD'): + # noinspection PyRedundantParentheses + if ((options.righttoleft and facing == 'left') or (not options.righttoleft and facing == 'right')) and\ + options.landscapemode: f.write("\n") splitCountUsed += 1 - f.write("\n") + if options.landscapemode: + f.write("\n") + else: + f.write("\n") elif entry.endswith("-2"): - f.write("\n") - if righttoleft: + if options.landscapemode: + f.write("\n") + else: + f.write("\n") + if options.righttoleft: facing = "right" else: facing = "left" else: - f.write("\n") + if options.landscapemode: + f.write("\n") + else: + f.write("\n") if facing == 'right': facing = 'left' else: facing = 'right' f.write("\n\n\n\n") f.close() - # finish with standard ePub folders os.mkdir(os.path.join(dstdir, 'META-INF')) f = open(os.path.join(dstdir, 'mimetype'), 'w') f.write('application/epub+zip') @@ -259,7 +294,8 @@ def applyImgOptimization(img, isSplit=False, toRight=False): img.cropWhiteSpace(10.0) if options.cutpagenumbers: img.cutPageNumber() - img.resizeImage(options.upscale, options.stretch, options.black_borders, isSplit, toRight) + img.resizeImage(options.upscale, options.stretch, options.black_borders, isSplit, toRight, options.landscapemode, + options.nopanelviewhq) img.optimizeImage(options.gamma) if not options.notquantize: img.quantizeImage() @@ -290,14 +326,12 @@ def dirImgProcess(path): if options.righttoleft: toRight1 = False toRight2 = True - else: - toRight1 = True - toRight2 = False - if options.righttoleft: if facing == "left": splitCount += 1 facing = "right" else: + toRight1 = True + toRight2 = False if facing == "right": splitCount += 1 facing = "left" @@ -321,41 +355,133 @@ def genEpubStruct(path): filelist = [] chapterlist = [] cover = None + _, deviceres, _, _, panelviewsize = image.ProfileData.Profiles[options.profile] os.mkdir(os.path.join(path, 'OEBPS', 'Text')) - f = open(os.path.join(path, 'OEBPS', 'Text', 'page_styles.css'), 'w') + f = open(os.path.join(path, 'OEBPS', 'Text', 'style.css'), 'w') + #DON'T COMPRESS CSS. KINDLE WILL FAIL TO PARSE IT. + #Generic Panel View support + Margins fix for Non-Kindle devices. f.writelines(["@page {\n", - " margin-bottom: 0;\n", - " margin-top: 0\n", - "}\n"]) - f.close() - f = open(os.path.join(path, 'OEBPS', 'Text', 'stylesheet.css'), 'w') - f.writelines([".kcc {\n", - " display: block;\n", - " margin-bottom: 0;\n", - " margin-left: 0;\n", - " margin-right: 0;\n", - " margin-top: 0;\n", - " padding-bottom: 0;\n", - " padding-left: 0;\n", - " padding-right: 0;\n", - " padding-top: 0;\n", - " text-align: left\n", + "margin-bottom: 0;\n", + "margin-top: 0\n", "}\n", - ".kcc1 {\n", - " display: block;\n", - " text-align: center\n", + "body {\n", + "display: block;\n", + "margin-bottom: 0;\n", + "margin-left: 0;\n", + "margin-right: 0;\n", + "margin-top: 0;\n", + "padding-bottom: 0;\n", + "padding-left: 0;\n", + "padding-right: 0;\n", + "padding-top: 0;\n", + "text-align: left\n", "}\n", - ".kcc2 {\n", - " height: auto;\n", - " width: auto\n", - "}\n"]) + "div.fs {\n", + "height: ", str(deviceres[1]), "px;\n", + "width: ", str(deviceres[0]), "px;\n", + "position: relative;\n", + "display: block;\n", + "text-align: center\n", + "}\n", + "div.fs a {\n", + "display: block;\n", + "width : 100%;\n", + "height: 100%;\n", + "}\n", + "div.fs div {\n", + "position: absolute;\n", + "}\n", + "img.singlePage {\n", + "position: absolute;\n", + "height: ", str(deviceres[1]), "px;\n", + "width: ", str(deviceres[0]), "px;\n", + "}\n", + "div.target-mag-parent {\n", + "width:100%;\n", + "height:100%;\n", + "display:none;\n", + "}\n", + "div.target-mag {\n", + "position: absolute;\n", + "display: block;\n", + "overflow: hidden;\n", + "}\n", + "div.target-mag img {\n", + "position: absolute;\n", + "height: ", str(panelviewsize[1]), "px;\n", + "width: ", str(panelviewsize[0]), "px;\n", + "}\n", + "#BoxTL {\n", + "top: 0;\n", + "left: 0;\n", + "height: 50%;\n", + "width: 50%;\n", + "}\n", + "#BoxTR {\n", + "top: 0;\n", + "right: 0;\n", + "height: 50%;\n", + "width: 50%;\n", + "}\n", + "#BoxBL {\n", + "bottom: 0;\n", + "left: 0;\n", + "height: 50%;\n", + "width: 50%;\n", + "}\n", + "#BoxBR {\n", + "bottom: 0;\n", + "right: 0;\n", + "height: 50%;\n", + "width: 50%;\n", + "}\n", + "#BoxTL-Panel {\n", + "top: 0;\n", + "left: 0;\n", + "height: 100%;\n", + "width: 100%;\n", + "}\n", + "#BoxTL-Panel img {\n", + "top: 0%;\n", + "left: 0%;\n", + "}\n", + "#BoxTR-Panel {\n", + "top: 0;\n", + "right: 0;\n", + "height: 100%;\n", + "width: 100%;\n", + "}\n", + "#BoxTR-Panel img {\n", + "top: 0%;\n", + "right: 0%;\n", + "}\n", + "#BoxBL-Panel {\n", + "bottom: 0;\n", + "left: 0;\n", + "height: 100%;\n", + "width: 100%;\n", + "}\n", + "#BoxBL-Panel img {\n", + "bottom: 0%;\n", + "left: 0%;\n", + "}\n", + "#BoxBR-Panel {\n", + "bottom: 0;\n", + "right: 0;\n", + "height: 100%;\n", + "width: 100%;\n", + "}\n", + "#BoxBR-Panel img {\n", + "bottom: 0%;\n", + "right: 0%;\n", + "}" + ]) f.close() for (dirpath, dirnames, filenames) in os.walk(os.path.join(path, 'OEBPS', 'Images')): chapter = False for afile in filenames: filename = getImageFileName(afile) if filename is not None: - # put credits at the end if "credit" in afile.lower(): os.rename(os.path.join(dirpath, afile), os.path.join(dirpath, 'ZZZ999_' + afile)) afile = 'ZZZ999_' + afile @@ -375,8 +501,8 @@ def genEpubStruct(path): convert = lambda text: int(text) if text.isdigit() else text alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)] filelist.sort(key=lambda name: (alphanum_key(name[0].lower()), alphanum_key(name[1].lower()))) - buildOPF(options.profile, path, options.title, filelist, cover, options.righttoleft) - if (options.profile == 'K4' or options.profile == 'KHD') and splitCount > 0: + buildOPF(options.profile, path, options.title, filelist, cover) + if options.landscapemode and splitCount > 0: filelist.append(buildBlankHTML(os.path.join(path, 'OEBPS', 'Text'))) @@ -425,11 +551,13 @@ def main(argv=None): usage = "Usage: %prog [options] comic_file|comic_folder" parser = OptionParser(usage=usage, version=__version__) parser.add_option("-p", "--profile", action="store", dest="profile", default="KHD", - help="Device profile (Choose one among K1, K2, K3, K4, KDX, KDXG or KHD) [Default=KHD]") + help="Device profile (Choose one among K1, K2, K3, K4NT, K4T, KDX, KDXG or KHD) [Default=KHD]") parser.add_option("-t", "--title", action="store", dest="title", default="defaulttitle", help="Comic title [Default=filename]") parser.add_option("-m", "--manga-style", action="store_true", dest="righttoleft", default=False, help="Manga style (Right-to-left reading and splitting) [Default=False]") + parser.add_option("--nopanelviewhq", action="store_true", dest="nopanelviewhq", default=False, + help="Disable high quality Panel View [Default=False]") parser.add_option("--noprocessing", action="store_false", dest="imgproc", default=True, help="Do not apply image preprocessing (Page splitting and optimizations) [Default=True]") parser.add_option("--nodithering", action="store_true", dest="notquantize", default=False, @@ -454,6 +582,7 @@ def main(argv=None): parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="Verbose output [Default=False]") options, args = parser.parse_args(argv) + checkOptions() if len(args) != 1: parser.print_help() return @@ -485,6 +614,22 @@ def main(argv=None): return epubpath +def checkOptions(): + global options + if options.profile == 'K4T' or options.profile == 'KHD': + options.landscapemode = True + else: + options.landscapemode = False + if options.profile == 'K3' or options.profile == 'K4NT': + #Real Panel View + options.panelview = True + else: + #Virtual Panel View + options.panelview = False + if options.profile == 'K1' or options.profile == 'K2' or options.profile == 'KDX' or options.profile == 'KDXG': + options.nopanelviewhq = True + + def getEpubPath(): global epub_path return epub_path diff --git a/kcc/gui.py b/kcc/gui.py index b9abcda..bc790c1 100644 --- a/kcc/gui.py +++ b/kcc/gui.py @@ -28,7 +28,6 @@ import comic2ebook import kindlestrip from image import ProfileData from subprocess import call -from subprocess import check_call import os import shutil import stat @@ -95,28 +94,30 @@ class MainWindow: self.options = { 'Aepub_only': IntVar(None, 0), 'Bmangastyle': IntVar(None, 0), - 'Cimage_preprocess': IntVar(None, 0), - 'Dnotquantize': IntVar(None, 0), - 'Eimage_gamma': DoubleVar(None, 0.0), - 'Fimage_upscale': IntVar(None, 0), - 'Gimage_stretch': IntVar(None, 0), - 'Hblack_borders': IntVar(None, 0), - 'Irotate': IntVar(None, 0), - 'Jnosplitrotate': IntVar(None, 0), - 'Kcut_page_numbers': IntVar(None, 0) + 'Cnopanelviewhq': IntVar(None, 0), + 'Dimage_preprocess': IntVar(None, 0), + 'Enotquantize': IntVar(None, 0), + 'Fimage_gamma': DoubleVar(None, 0.0), + 'Gimage_upscale': IntVar(None, 0), + 'Himage_stretch': IntVar(None, 0), + 'Iblack_borders': IntVar(None, 0), + 'Jrotate': IntVar(None, 0), + 'Knosplitrotate': IntVar(None, 0), + 'Lcut_page_numbers': IntVar(None, 0) } self.optionlabels = { 'Aepub_only': "Generate EPUB only", - 'Cimage_preprocess': "Disable image optimizations", - 'Dnotquantize': "Disable image quantization", - 'Jnosplitrotate': "Disable splitting and rotation", - 'Irotate': "Rotate images instead splitting them", - 'Kcut_page_numbers': "Disable page numbers cutting", 'Bmangastyle': "Manga mode", - 'Eimage_gamma': "Custom gamma correction", - 'Fimage_upscale': "Allow image upscaling", - 'Gimage_stretch': "Stretch images", - 'Hblack_borders': "Use black borders" + 'Cnopanelviewhq': "Disable high quality Panel View", + 'Dimage_preprocess': "Disable image optimizations", + 'Enotquantize': "Disable image quantization", + 'Fimage_gamma': "Custom gamma correction", + 'Gimage_upscale': "Allow image upscaling", + 'Himage_stretch': "Stretch images", + 'Iblack_borders': "Use black borders", + 'Jrotate': "Rotate images instead splitting them", + 'Knosplitrotate': "Disable splitting and rotation", + 'Lcut_page_numbers': "Disable page numbers cutting" } self.optionsButtons = {} for key in sorted(self.options): @@ -161,27 +162,29 @@ class MainWindow: return profilekey = ProfileData.ProfileLabels[self.profile.get()] argv = ["-p", profilekey] - if self.options['Eimage_gamma'].get() != 0.0: - argv.append("--gamma") - argv.append(self.options['Eimage_gamma'].get()) - if self.options['Cimage_preprocess'].get() == 1: - argv.append("--noprocessing") - if self.options['Dnotquantize'].get() == 1: - argv.append("--nodithering") - if self.options['Jnosplitrotate'].get() == 1: - argv.append("--nosplitrotate") - if self.options['Irotate'].get() == 1: - argv.append("--rotate") - if self.options['Kcut_page_numbers'].get() == 1: - argv.append("--nocutpagenumbers") if self.options['Bmangastyle'].get() == 1: argv.append("-m") - if self.options['Fimage_upscale'].get() == 1: + if self.options['Cnopanelviewhq'].get() == 1: + argv.append("--nopanelviewhq") + if self.options['Dimage_preprocess'].get() == 1: + argv.append("--noprocessing") + if self.options['Enotquantize'].get() == 1: + argv.append("--nodithering") + if self.options['Fimage_gamma'].get() != 0.0: + argv.append("--gamma") + argv.append(self.options['Fimage_gamma'].get()) + if self.options['Gimage_upscale'].get() == 1: argv.append("--upscale") - if self.options['Gimage_stretch'].get() == 1: + if self.options['Himage_stretch'].get() == 1: argv.append("--stretch") - if self.options['Hblack_borders'].get() == 1: + if self.options['Iblack_borders'].get() == 1: argv.append("--blackborders") + if self.options['Jrotate'].get() == 1: + argv.append("--rotate") + if self.options['Knosplitrotate'].get() == 1: + argv.append("--nosplitrotate") + if self.options['Lcut_page_numbers'].get() == 1: + argv.append("--nocutpagenumbers") errors = False left_files = len(self.filelist) filenum = 0 @@ -206,10 +209,10 @@ class MainWindow: continue if self.options['Aepub_only'].get() == 0: try: - if os.path.getsize(epub_path) > 335544320: - # do not call kindlegen if source is bigger than 320MB + if os.path.getsize(epub_path) > 314572800: + # do not call kindlegen if source is bigger than 300MB tkMessageBox.showwarning('KindleGen Warning', - "ePub file %s is bigger than 320MB, not suitable for kindlegen" % + "ePub file %s is bigger than 300MB, not suitable for kindlegen" % epub_path) continue retcode = call("kindlegen \"" + epub_path + "\"", shell=True) diff --git a/kcc/image.py b/kcc/image.py index 94febca..743c124 100755 --- a/kcc/image.py +++ b/kcc/image.py @@ -20,7 +20,7 @@ __copyright__ = '2012-2013, Ciro Mattia Gonano ' __docformat__ = 'restructuredtext en' import os -from PIL import Image, ImageOps, ImageDraw, ImageStat +from PIL import Image, ImageOps, ImageStat class ImageFlags: @@ -77,20 +77,22 @@ class ProfileData: ] Profiles = { - 'K1': ("Kindle", (600, 800), Palette4, 1.8), - 'K2': ("Kindle 2", (600, 800), Palette15, 1.8), - 'K3': ("Kindle 3/Keyboard", (600, 800), Palette16, 1.8), - 'K4': ("Kindle 4/NT/Touch", (600, 800), Palette16, 1.8), - 'KHD': ("Kindle Paperwhite", (758, 1024), Palette16, 1.8), - 'KDX': ("Kindle DX", (824, 1200), Palette15, 1.8), - 'KDXG': ("Kindle DXG", (824, 1200), Palette16, 1.8) + 'K1': ("Kindle 1", (600, 800), Palette4, 1.8, (900, 1200)), + 'K2': ("Kindle 2", (600, 800), Palette15, 1.8, (900, 1200)), + 'K3': ("Kindle Keyboard", (600, 800), Palette16, 1.8, (900, 1200)), + 'K4NT': ("Kindle Non-Touch", (600, 800), Palette16, 1.8, (900, 1200)), + 'K4T': ("Kindle Touch", (600, 800), Palette16, 1.8, (900, 1200)), + 'KHD': ("Kindle Paperwhite", (758, 1024), Palette16, 1.8, (1137, 1536)), + 'KDX': ("Kindle DX", (824, 1200), Palette15, 1.8, (1236, 1800)), + 'KDXG': ("Kindle DXG", (824, 1200), Palette16, 1.8, (1236, 1800)) } ProfileLabels = { - "Kindle": 'K1', + "Kindle 1": 'K1', "Kindle 2": 'K2', "Kindle 3/Keyboard": 'K3', - "Kindle 4/NT/Touch": 'K4', + "Kindle 4/Non-Touch": 'K4NT', + "Kindle 4/Touch": 'K4T', "Kindle Paperwhite": 'KHD', "Kindle DX": 'KDX', "Kindle DXG": 'KDXG' @@ -101,7 +103,7 @@ class ComicPage: def __init__(self, source, device): try: self.profile = device - self.profile_label, self.size, self.palette, self.gamma = ProfileData.Profiles[device] + self.profile_label, self.size, self.palette, self.gamma, self.panelviewsize = ProfileData.Profiles[device] except KeyError: raise RuntimeError('Unexpected output device %s' % device) try: @@ -141,46 +143,48 @@ class ComicPage: palImg.putpalette(self.palette) self.image = self.image.quantize(palette=palImg) - def resizeImage(self, upscale=False, stretch=False, black_borders=False, isSplit=False, toRight=False): + def resizeImage(self, upscale=False, stretch=False, black_borders=False, isSplit=False, toRight=False, + landscapeMode=False, noPanelViewHQ=False): method = Image.ANTIALIAS if black_borders: fill = 'black' else: fill = 'white' + if noPanelViewHQ: + size = (self.size[0], self.size[1]) + else: + size = (self.panelviewsize[0], self.panelviewsize[1]) + if isSplit and landscapeMode: + upscale = True if self.image.size[0] <= self.size[0] and self.image.size[1] <= self.size[1]: if not upscale: - if isSplit and (self.profile == 'K4' or self.profile == 'KHD'): - 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) + 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 - + method = Image.BILINEAR if stretch: # if stretching call directly resize() without other considerations. - self.image = self.image.resize(self.size, method) + self.image = self.image.resize(size, method) return self.image - ratioDev = float(self.size[0]) / float(self.size[1]) if (float(self.image.size[0]) / float(self.image.size[1])) < ratioDev: - diff = int(self.image.size[1] * ratioDev) - self.image.size[0] - if isSplit and (self.profile == 'K4' or self.profile == 'KHD'): - diff = 2 - self.image = ImageOps.expand(self.image, border=(diff / 2, 0), fill=fill) + if isSplit and landscapeMode: + diff = int(self.image.size[1] * ratioDev) - self.image.size[0] + self.image = ImageOps.expand(self.image, border=(diff / 2, 0), fill=fill) + tempImg = Image.new(self.image.mode, (self.image.size[0] + diff, self.image.size[1]), fill) + if toRight: + tempImg.paste(self.image, (diff, 0)) + else: + tempImg.paste(self.image, (0, 0)) + self.image = tempImg + else: + diff = int(self.image.size[1] * ratioDev) - self.image.size[0] + self.image = ImageOps.expand(self.image, border=(diff / 2, 0), fill=fill) elif (float(self.image.size[0]) / float(self.image.size[1])) > ratioDev: diff = int(self.image.size[0] / ratioDev) - self.image.size[1] self.image = ImageOps.expand(self.image, border=(0, diff / 2), fill=fill) - self.image = ImageOps.fit(self.image, self.size, method=method, centering=(0.5, 0.5)) + self.image = ImageOps.fit(self.image, size, method=method, centering=(0.5, 0.5)) return self.image def splitPage(self, targetdir, righttoleft=False, rotate=False): @@ -220,29 +224,6 @@ class ComicPage: else: return None - def frameImage(self): - foreground = tuple(self.palette[:3]) - background = tuple(self.palette[-3:]) - widthDev, heightDev = self.size - widthImg, heightImg = self.image.size - pastePt = ( - max(0, (widthDev - widthImg) / 2), - max(0, (heightDev - heightImg) / 2) - ) - corner1 = ( - pastePt[0] - 1, - pastePt[1] - 1 - ) - corner2 = ( - pastePt[0] + widthImg + 1, - pastePt[1] + heightImg + 1 - ) - imageBg = Image.new(self.image.mode, self.size, background) - imageBg.paste(self.image, pastePt) - draw = ImageDraw.Draw(imageBg) - draw.rectangle([corner1, corner2], outline=foreground) - self.image = imageBg - def cutPageNumber(self): widthImg, heightImg = self.image.size delta = 2 @@ -335,37 +316,60 @@ class ComicPage: # print "New size: %sx%s"%(self.image.size[0],self.image.size[1]) return self.image - def addProgressbar(self, file_number, files_totalnumber, size, howoften): - if file_number // howoften != float(file_number) / howoften: - return self.image - white = (255, 255, 255) - black = (0, 0, 0) - widthDev, heightDev = size - widthImg, heightImg = self.image.size - pastePt = ( - max(0, (widthDev - widthImg) / 2), - max(0, (heightDev - heightImg) / 2) - ) - imageBg = Image.new('RGB', size, white) - imageBg.paste(self.image, pastePt) - self.image = imageBg - widthImg, heightImg = self.image.size - draw = ImageDraw.Draw(self.image) - #Black rectangle - draw.rectangle([(0, heightImg - 3), (widthImg, heightImg)], outline=black, fill=black) - #White rectangle - draw.rectangle([(widthImg * file_number / files_totalnumber, heightImg - 3), (widthImg - 1, heightImg)], - outline=black, fill=white) - #Making notches - for i in range(1, 10): - if i <= (10 * file_number / files_totalnumber): - notch_colour = white # White - else: - notch_colour = black # Black - draw.line([(widthImg * float(i) / 10, heightImg - 3), (widthImg * float(i) / 10, heightImg)], - fill=notch_colour) - #The 50% - if i == 5: - draw.rectangle([(widthImg / 2 - 1, heightImg - 5), (widthImg / 2 + 1, heightImg)], - outline=black, fill=notch_colour) - return self.image + # def addProgressbar(self, file_number, files_totalnumber, size, howoften): + # if file_number // howoften != float(file_number) / howoften: + # return self.image + # white = (255, 255, 255) + # black = (0, 0, 0) + # widthDev, heightDev = size + # widthImg, heightImg = self.image.size + # pastePt = ( + # max(0, (widthDev - widthImg) / 2), + # max(0, (heightDev - heightImg) / 2) + # ) + # imageBg = Image.new('RGB', size, white) + # imageBg.paste(self.image, pastePt) + # self.image = imageBg + # widthImg, heightImg = self.image.size + # draw = ImageDraw.Draw(self.image) + # #Black rectangle + # draw.rectangle([(0, heightImg - 3), (widthImg, heightImg)], outline=black, fill=black) + # #White rectangle + # draw.rectangle([(widthImg * file_number / files_totalnumber, heightImg - 3), (widthImg - 1, heightImg)], + # outline=black, fill=white) + # #Making notches + # for i in range(1, 10): + # if i <= (10 * file_number / files_totalnumber): + # notch_colour = white # White + # else: + # notch_colour = black # Black + # draw.line([(widthImg * float(i) / 10, heightImg - 3), (widthImg * float(i) / 10, heightImg)], + # fill=notch_colour) + # #The 50% + # if i == 5: + # draw.rectangle([(widthImg / 2 - 1, heightImg - 5), (widthImg / 2 + 1, heightImg)], + # outline=black, fill=notch_colour) + # return self.image + # + # def frameImage(self): + # foreground = tuple(self.palette[:3]) + # background = tuple(self.palette[-3:]) + # widthDev, heightDev = self.size + # widthImg, heightImg = self.image.size + # pastePt = ( + # max(0, (widthDev - widthImg) / 2), + # max(0, (heightDev - heightImg) / 2) + # ) + # corner1 = ( + # pastePt[0] - 1, + # pastePt[1] - 1 + # ) + # corner2 = ( + # pastePt[0] + widthImg + 1, + # pastePt[1] + heightImg + 1 + # ) + # imageBg = Image.new(self.image.mode, self.size, background) + # imageBg.paste(self.image, pastePt) + # draw = ImageDraw.Draw(imageBg) + # draw.rectangle([corner1, corner2], outline=foreground) + # self.image = imageBg