Skip to content

Commit

Permalink
Avoid margins when converting figure
Browse files Browse the repository at this point in the history
  • Loading branch information
kthoden committed Nov 15, 2021
1 parent b48b8bb commit 4c8c93a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/imxml2django.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: <2021-07-09 13:48:22 (kthoden)>
# Time-stamp: <2021-10-26 14:09:17 (kthoden)>

"""
Create an XML file that can be inserted into the Django database
Expand Down Expand Up @@ -1542,7 +1542,8 @@ def bring_footnote_down_django(footnote, fragment, footnote_number, object_numbe
PUBLICATION_DIR / strInlineElementDirName / strInlineElementFileName,
TEMP_DIR,
GM_PATH,
PDFCROP_EXEC
PDFCROP_EXEC,
margin=False
)
strInlineElementFileName = strInlineElementFileName.replace(".pdf", ".png")

Expand All @@ -1556,9 +1557,10 @@ def bring_footnote_down_django(footnote, fragment, footnote_number, object_numbe
# shutil.copy(os.getcwd() + "/" + strInlineElementDirName + "/" + strInlineElementFileName, os.getcwd() + "/CONVERT/django/images/embedded/" + strInlineElementDirName + strInlineElementFileName)
strNewImagePath = OUTPUT_DIR / "images/embedded" / (strInlineElementSubDirName + strInlineElementFileName)
# strNewImagePath = os.getcwd() + "/CONVERT/django/images/embedded/" + strInlineElementDirName + strInlineElementFileName
strCommand = GM_PATH + " convert " + str(strNewImagePath) + " -resize 20x20 " + str(strNewImagePath)
listArguments = shlex.split(strCommand)
subprocess.check_output(listArguments, shell=False)
# strCommand = GM_PATH + " convert " + str(strNewImagePath) + " -resize 20x20 " + str(strNewImagePath)
# listArguments = shlex.split(strCommand)
# subprocess.check_output(listArguments, shell=False)

# Change EOAcitenumeric into a span to create approriate link
xmlEOAcitenumerics = xmlEOAchapter.findall(".//EOAcitenumeric")
for xmlEOAcitenumeric in xmlEOAcitenumerics:
Expand Down
7 changes: 6 additions & 1 deletion src/utils/libeoaconvert.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def sanitizeImage(
tmp_dir,
GM_PATH,
PDFCROP_EXEC,
margin=True
# TL_PATH
):
"""Adjust and convert image for epub standard"""
Expand Down Expand Up @@ -125,8 +126,12 @@ def sanitizeImage(
strNewImagepath = os.path.splitext(str(strImagepath))[0]
clipped_file = str(strImagepath).replace(".pdf", "-clipped.pdf")

if margin:
margin_value = 10
else:
margin_value = 1
exec_command(
f"{PDFCROP_EXEC} --margins 10 --clip --hires {strImagepath} {clipped_file}",
f"{PDFCROP_EXEC} --margins {margin_value} --clip --hires {strImagepath} {clipped_file}",
# wd = tmp_image_dir
)
exec_command(
Expand Down

0 comments on commit 4c8c93a

Please sign in to comment.