From 812fecec5fd9163ea7a2b42072275bde67d7aa46 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 7 Jun 2023 20:30:22 +0530 Subject: [PATCH] Kindle output: Only re-encode JPEG images with EXIF metadata if the metadata contains actual transpose operations. Fixes #2023189 [[EPUB->MOBI] Calibre MOBI file Size too small](https://bugs.launchpad.net/calibre/+bug/2023189) --- src/calibre/ebooks/mobi/writer2/resources.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/mobi/writer2/resources.py b/src/calibre/ebooks/mobi/writer2/resources.py index 710c510374..f75ba43aa4 100644 --- a/src/calibre/ebooks/mobi/writer2/resources.py +++ b/src/calibre/ebooks/mobi/writer2/resources.py @@ -27,9 +27,11 @@ def process_jpegs_for_amazon(data: bytes) -> bytes: # Amazon's MOBI renderer can't render JPEG images without JFIF metadata # and images with EXIF data dont get displayed on the cover screen changed = not img.info - if hasattr(img, '_getexif') and img._getexif(): - changed = True - img = ImageOps.exif_transpose(img) + if hasattr(img, 'getexif'): + exif = img.getexif() + if exif.get(0x0112) in (2,3,4,5,6,7,8): + changed = True + img = ImageOps.exif_transpose(img) if changed: out = BytesIO() img.save(out, 'JPEG')