From 005aa31e663139841779174436f7b1b50b7d7527 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Tue, 27 Dec 2022 15:49:48 +0100 Subject: [PATCH] Detect JPEG/MPO images as normal JPEG files Some cameras store multiple images in JPEG photos, using the MPO format in EXIF metadata. As Pillow supports this format, it sets the "MPO" format attribute to the image object, not the "JPEG" one. This leads to a useless PNG conversion, as MPO are (often, always?) supposed to be "normal" JPEG files. See https://github.com/python-pillow/Pillow/issues/1138. Fix #1777. --- weasyprint/pdf/stream.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weasyprint/pdf/stream.py b/weasyprint/pdf/stream.py index 518d5d3f1c..3b6059b9d0 100644 --- a/weasyprint/pdf/stream.py +++ b/weasyprint/pdf/stream.py @@ -423,7 +423,7 @@ def add_image(self, pillow_image, image_rendering, optimize_size): }) optimize = 'images' in optimize_size - if pillow_image.format == 'JPEG': + if pillow_image.format in ('JPEG', 'MPO'): extra['Filter'] = '/DCTDecode' image_file = io.BytesIO() pillow_image.save(image_file, format='JPEG', optimize=optimize)