From 6e810429893a795621a6b7175897ef799a25b1e8 Mon Sep 17 00:00:00 2001 From: glubsy Date: Thu, 6 Aug 2020 00:23:49 +0200 Subject: [PATCH 1/2] Workaround for #630 * In some cases, the function dump_IFD() in core/pe/exif.py assigns a string instead of an int as "values". * This value is then used as _cached_orientation in core/pe/photo.py in _get_orientation(). * The method _plat_get_blocks() in qt/pe/photo.py was only expecting an integer for the orientation argument, so we work around the issue for now by ignoring the value if it's a string. --- qt/pe/photo.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qt/pe/photo.py b/qt/pe/photo.py index dcf71c41..3408faf6 100644 --- a/qt/pe/photo.py +++ b/qt/pe/photo.py @@ -29,6 +29,10 @@ class File(PhotoBase): def _plat_get_blocks(self, block_count_per_side, orientation): image = QImage(str(self.path)) image = image.convertToFormat(QImage.Format_RGB888) + if type(orientation) == str: + logging.warning("Orientation for file '%s' was a str '%s', not an int!", + str(self.path), orientation) + return getblocks(image, block_count_per_side) # MYSTERY TO SOLVE: For reasons I cannot explain, orientations 5 and 7 don't work for # duplicate scanning. The transforms seems to work fine (if I try to save the image after # the transform, we see that the image has been correctly flipped and rotated), but the From 3333d265571f08894faf2b79509f7f74da653891 Mon Sep 17 00:00:00 2001 From: glubsy Date: Fri, 7 Aug 2020 00:37:37 +0200 Subject: [PATCH 2/2] Try to handle conversion to int or fail gracefully --- qt/pe/photo.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/qt/pe/photo.py b/qt/pe/photo.py index 3408faf6..a829f21e 100644 --- a/qt/pe/photo.py +++ b/qt/pe/photo.py @@ -30,9 +30,14 @@ class File(PhotoBase): image = QImage(str(self.path)) image = image.convertToFormat(QImage.Format_RGB888) if type(orientation) == str: - logging.warning("Orientation for file '%s' was a str '%s', not an int!", + logging.warning("Orientation for file '%s' was a str '%s', not an int.", str(self.path), orientation) - return getblocks(image, block_count_per_side) + try: + orientation = int(orientation) + except Exception as e: + logging.exception("Skipping transformation because could not \ +convert str to int. %s", e) + return getblocks(image, block_count_per_side) # MYSTERY TO SOLVE: For reasons I cannot explain, orientations 5 and 7 don't work for # duplicate scanning. The transforms seems to work fine (if I try to save the image after # the transform, we see that the image has been correctly flipped and rotated), but the