From 4cd968daa6759057d2c58b6a966fc4d343545add Mon Sep 17 00:00:00 2001 From: SNoiraud Date: Tue, 9 Feb 2021 11:21:38 +0100 Subject: [PATCH 1/2] image magic exception if file not found --- gramps/gen/utils/image.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gramps/gen/utils/image.py b/gramps/gen/utils/image.py index 7a953f580..202d628f0 100644 --- a/gramps/gen/utils/image.py +++ b/gramps/gen/utils/image.py @@ -179,8 +179,9 @@ def image_size(source): img = img[found:] size = re.search('(\d+)\s*x\s*(\d+)', img).groups() return (int(size[0]), int(size[1])) - except ImportError: - # python-magic is not installed. So Trying to get image size with Gdk. + except (ImportError, FileNotFoundError): + # python-magic is not installed or the file does not exist. + # So Trying to get image size with Gdk. try: img = GdkPixbuf.Pixbuf.new_from_file(source) width = img.get_width() From ace772812aea2b343b1e4da8446f75e1f8419249 Mon Sep 17 00:00:00 2001 From: SNoiraud Date: Tue, 9 Feb 2021 12:54:44 +0100 Subject: [PATCH 2/2] image magic: add bmp and tiff + Readme --- README.md | 18 ++++++++++++++++++ gramps/gen/utils/image.py | 8 +++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6fc846259..177d10896 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,24 @@ The following packages are optional: Python bindings of fontconfig are required for displaying genealogical symbols +* **magic** + + Python magic bindings required to have better performances with image + processing. + If this module is not available, we continue to use Gdk. + This avoid to load the image in memory. This is a real improvement + when we have many big images. + Used in odfdoc, rtfdoc and webreport and tested with png, gif, jpeg, bmp, tiff + # + # file size with magic without (Gdk) ratio + # example 1 : 256k 0.00080 0.00575 7 + # example 2 : 21M 0.00171 0.55860 326 + + Debian, Ubuntu, ... : python3-magic + Fedora, Redhat, ... : python3-magic + openSUSE : python-magic + ArchLinux : python-magic + Optional packages required by Third-party Addons ------------------------------------------------ diff --git a/gramps/gen/utils/image.py b/gramps/gen/utils/image.py index 202d628f0..a15ce36ec 100644 --- a/gramps/gen/utils/image.py +++ b/gramps/gen/utils/image.py @@ -168,12 +168,18 @@ def image_size(source): # For performance reasons, we'll try to get image size from magic. # This avoid to load the image in memory. This is a real improvement # when we have many big images. - # Used in odfdoc, rtfdoc and webreport and tested with png, gif, jpeg + # Used in odfdoc, rtfdoc and webreport and tested with png, gif, jpeg, + # bmp, tiff # # file size with magic without (Gdk) ratio # example 1 : 256k 0.00080 0.00575 7 # example 2 : 21M 0.00171 0.55860 326 img = magic.from_file(source) + found = img.find("TIFF") + if found == 0: + width = re.search('width=(\d+)', img).groups() + height = re.search('height=(\d+)', img).groups() + return (int(width[0]), int(height[0])) found = img.find("precision") if found > 0: img = img[found:]