Skip to content

Commit

Permalink
latex treedoc: convert images to thumbnails for embedding
Browse files Browse the repository at this point in the history
Images are included by the latex code in full into the rendering,
instead of only the rectangle selected in gramps' media DB. Having lots
of big photos with small faces in my setup, this leads to unreasonably
huge PDF files with unrecognizably small faces in them.

Also, some characters (e.g. comma, spaces) in filepaths might trouble
the latex parser, see 75921ce and 2da93aa -- using thumbnails this
is circumvented.

However, note this makes the resulting .tex file not standalone anymore.
  • Loading branch information
azrdev committed Nov 18, 2023
1 parent 892fc27 commit 99a9016
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions gramps/gen/plug/docgen/treedoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from ...constfunc import win
from ...config import config
from ...const import GRAMPS_LOCALE as glocale
from ...utils.thumbnails import get_thumbnail_path

_ = glocale.translation.gettext

Expand Down Expand Up @@ -589,12 +590,15 @@ def write_node(self, db, level, node_type, person, marriage_flag, option_list=No
self.write(level + 1, "comment = {%s},\n" % escape(attr.get_value()))
for mediaref in person.get_media_list():
media = db.get_media_from_handle(mediaref.ref)
path = media_path_full(db, media.get_path())
if os.path.isfile(path):
if win():
path = path.replace("\\", "/")
self.write(level + 1, "image = {%s},\n" % path)
break # first image only
if media.get_mime_type().startswith('image'):
path = get_thumbnail_path(
media_path_full(db, media.get_path()),
rectangle=mediaref.get_rectangle())
if os.path.isfile(path):
if win():
path = path.replace("\\", "/")
self.write(level+1, "image = {%s},\n" % path)
break # first image only
self.write(level, "}\n")

def write_event(self, db, level, event):
Expand Down

0 comments on commit 99a9016

Please sign in to comment.