From f157ced05d5113172c6ccd32c8f7b6a0af11c1c9 Mon Sep 17 00:00:00 2001 From: Leo Date: Tue, 17 Oct 2023 11:31:51 +0200 Subject: [PATCH] ignore RGB icc profile for grayscale jpegs produced by SmartAlbums closes: #175 --- src/img2pdf.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/img2pdf.py b/src/img2pdf.py index 68e94f4..42c695a 100755 --- a/src/img2pdf.py +++ b/src/img2pdf.py @@ -1478,6 +1478,26 @@ def get_imgmetadata( ) logger.warning("https://gitlab.gnome.org/GNOME/gimp/-/issues/3438") iccp = None + # SmartAlbums old version (found 2.2.6) exports JPG with only 1 compone + # with an RGB ICC profile which is useless. + # This produces an error in Adobe Acrobat, so we ignore it with a warning. + if iccp is not None and ( + (color == Colorspace["L"] and imgformat == ImageFormat.JPEG) + ): + exifsoft = None + if hasattr(imgdata, "_getexif") and imgdata._getexif() is not None: + for tag, value in imgdata._getexif().items(): + if TAGS.get(tag, tag) == "Software": + exifsoft = value + with io.BytesIO(iccp) as f: + prf = ImageCms.ImageCmsProfile(f) + if (prf.profile.model and "sRGB" in prf.profile.model) and ( + exifsoft and "SmartAlbums" in exifsoft + ): + logger.warning( + "Ignoring RGB ICC profile in Grayscale JPG created by SmartAlbums" + ) + iccp = None logger.debug("width x height = %dpx x %dpx", imgwidthpx, imgheightpx)