Skip to content

Commit

Permalink
Files for epub will be converted to a smaller size
Browse files Browse the repository at this point in the history
  • Loading branch information
Klaus Thoden committed Mar 8, 2018
1 parent b8704ef commit ec1b820
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 5 additions & 4 deletions libeoaconvert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion tralics2epub.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 = """<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%" viewBox="0 0 573 800" preserveAspectRatio="xMidYMid meet"></svg>"""
Expand Down

0 comments on commit ec1b820

Please sign in to comment.