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)

This commit is contained in:
Kovid Goyal 2023-06-07 20:30:22 +05:30
parent 92d62bf9f1
commit 812fecec5f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -27,9 +27,11 @@ def process_jpegs_for_amazon(data: bytes) -> bytes:
# Amazon's MOBI renderer can't render JPEG images without JFIF metadata # Amazon's MOBI renderer can't render JPEG images without JFIF metadata
# and images with EXIF data dont get displayed on the cover screen # and images with EXIF data dont get displayed on the cover screen
changed = not img.info changed = not img.info
if hasattr(img, '_getexif') and img._getexif(): if hasattr(img, 'getexif'):
changed = True exif = img.getexif()
img = ImageOps.exif_transpose(img) if exif.get(0x0112) in (2,3,4,5,6,7,8):
changed = True
img = ImageOps.exif_transpose(img)
if changed: if changed:
out = BytesIO() out = BytesIO()
img.save(out, 'JPEG') img.save(out, 'JPEG')