From 99a901644661ddeedb6d516c15cc9aa47a62b79d Mon Sep 17 00:00:00 2001 From: azrdev Date: Sat, 18 Nov 2023 22:36:20 +0100 Subject: [PATCH] latex treedoc: convert images to thumbnails for embedding 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 75921ceaf and 2da93aad1 -- using thumbnails this is circumvented. However, note this makes the resulting .tex file not standalone anymore. --- gramps/gen/plug/docgen/treedoc.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/gramps/gen/plug/docgen/treedoc.py b/gramps/gen/plug/docgen/treedoc.py index 8d6a76a7909..8c733d9c035 100644 --- a/gramps/gen/plug/docgen/treedoc.py +++ b/gramps/gen/plug/docgen/treedoc.py @@ -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 @@ -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):