From ec1b820b69b72f815a5a985008548ad1ce3061d5 Mon Sep 17 00:00:00 2001 From: Klaus Thoden Date: Thu, 8 Mar 2018 16:16:31 +0100 Subject: [PATCH] Files for epub will be converted to a smaller size --- libeoaconvert.py | 9 +++++---- tralics2epub.py | 6 +++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/libeoaconvert.py b/libeoaconvert.py index 27329fd..fba1c12 100644 --- a/libeoaconvert.py +++ b/libeoaconvert.py @@ -70,21 +70,22 @@ def get_bigfoot_data(chapter): def sanitizeImage(strImagepath, GM_PATH, TL_PATH): """Adjust and convert image for epub standard""" + logging.debug(strImagepath) strCommand = GM_PATH + " identify -format \"%w\" " + strImagepath listArguments = shlex.split(strCommand) exeShell = subprocess.check_output(listArguments, shell=False, universal_newlines=True) intImageWidth = int(exeShell) - if intImageWidth > 1500: - strCommand = GM_PATH + " convert " + strImagepath + " -resize 1500x\\> " + strImagepath + if intImageWidth > 700: + strCommand = GM_PATH + " convert " + strImagepath + " -resize 700x\\> " + strImagepath listArguments = shlex.split(strCommand) subprocess.check_output(listArguments, shell=False) strCommand = GM_PATH + " identify -format \"%h\" " + strImagepath listArguments = shlex.split(strCommand) exeShell = subprocess.check_output(listArguments, shell=False, universal_newlines=True) intImageHeight = int(exeShell) - if intImageHeight > 2000: - strCommand = GM_PATH + " convert " + strImagepath + " -resize x2000\\> " + strImagepath + if intImageHeight > 1000: + strCommand = GM_PATH + " convert " + strImagepath + " -resize x1000\\> " + strImagepath listArguments = shlex.split(strCommand) subprocess.check_output(listArguments, shell=False) strCommand = GM_PATH + " identify -format \"%m\" " + strImagepath diff --git a/tralics2epub.py b/tralics2epub.py index 17046a9..5040dd6 100755 --- a/tralics2epub.py +++ b/tralics2epub.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8; mode: python -*- -# Time-stamp: <2018-02-09 16:00:16 (kthoden)> +# Time-stamp: <2018-02-28 15:45:37 (kthoden)> import os import sys @@ -1143,7 +1143,11 @@ class FootnoteError(Exception): strImageFileDir = os.path.dirname(strImageFile) strImageFileDir = re.sub("/", "", strImageFileDir) strImageFileName = os.path.basename(strImageFile) + # hier shutil.copy(os.getcwd() + "/" + strImageFile, os.getcwd() + "/CONVERT/epub/OEBPS/images/" + strImageFileDir + strImageFileName) + + strImageFilepath = libeoaconvert.sanitizeImage(os.getcwd() + "/CONVERT/epub/OEBPS/images/" + strImageFileDir + strImageFileName, GM_PATH, TL_PATH) + # Add copied file to contentopf contentopf = addToContentopf(contentopf, "images/" + strImageFileDir + strImageFileName, strImageFileDir + strImageFileName, "jpg") strSVGTemplate = """"""