Skip to content

Commit

Permalink
Detect JPEG/MPO images as normal JPEG files
Browse files Browse the repository at this point in the history
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 python-pillow/Pillow#1138.

Fix #1777.
  • Loading branch information
liZe committed Dec 27, 2022
1 parent 274ba54 commit 005aa31
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion weasyprint/pdf/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 005aa31

Please sign in to comment.